2

I have a DataTable. I want to print it to the interface Maui. How can I do that?


In WPF I did it like this on C#:

gridPrinted.ItemsSource = myclass.GetDataTable().AsDataView();

WPF XAML:

<DataGrid x:Name="gridPrinted" Grid.Row="1" LoadingRow="gridPrinted_LoadingRow" CanUserAddRows="False"/>

In Maui, I have been trying to use CollectionView like this:

C# code:

DataView dat = myclass.GetDataTable().AsDataView();

XAML code:

            <CollectionView ItemsSource="{Binding dat}">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid Padding="10">
                            <Label Grid.Column="1"
                                Text="{Binding label}"
                                FontAttributes="Bold" />
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>

However nothing happens. No table is generated, but also no errors, no exceptions, nothing. How can I print that table?

1 Answers1

2

We couldn't see the other code of your app, but you can try to check the following aspects:

1.DataView dat = myclass.GetDataTable().AsDataView();

Here, the returned type of myclass.GetDataTable().AsDataView() should be a list,for example:

public ObservableCollection<YourItem>  items;

or

 System.Collections.Generic.IList<YourItem> items;

2.make sure set the BindingContext for your page;

3.make sure there is a returned value for the ItemsSource of your CollectionView.

  myclass.GetDataTable().AsDataView();
Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19
  • 2
    Thanks for the suggestions. I have created an IEnumerable type using the rows and managed to make a vertical list with as many items as there are rows, which means I can make a table with a dynamical number of lines. However, I have been struggling to make it have a dynamical number of columns. I can print one column of the table or two using Labels, and binding them to the vector position of the row, but nothing dynamical. I have made another question for this. Do you have any suggestion? –  Jun 16 '22 at 22:56