Bind a DB table to a collection view in .net maui

Anonymous
2022-10-12T13:42:19.133+00:00

I am new to database but i learned alot about it and how to use it with windows forms it works great with it but when it comes to .net maui i can not bind any data table to a collection view or a list so how can i do it?

   tb.Columns.Add("emp_no",typeof(int));  
   tb.Columns.Add("name");  
   tb.Rows.Add(new object[] {1,"aed"});  
   tb.Rows.Add(new object[] { 2, "ham" });  
   tb.Rows.Add(new object[] { 3, "a2r" });  
   tb.Rows.Add(new object[] { 4, "o24mer" });  
   tb.Rows.Add(new object[] { 5, "ans57" });  

I use CollectionView Like why is it not working like forms?

   <CollectionView  ItemsSource="{Binding tb.Columns}">  
           <CollectionView.ItemTemplate >  
               <DataTemplate >  
                   <StackLayout>                     
                       <Label Text="{Binding tb.Columns[0].Value}" />  
                       <Label Text="{Binding tb.Columns[1].Value}"/>  
                   </StackLayout>                   
               </DataTemplate>         
           </CollectionView.ItemTemplate>  
       </CollectionView>  
Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-10-13T02:34:37.26+00:00

    Hello,

    You need to get these data to a collection such as List or ObservableCollection from the database in your project, then you can bind it in in your ViewModel.

    For example. if you use Sqlite Database, you need to get data from database to List like this document: Data manipulation methods, after that, you can get this List in your ViewModel and bind it to your CollectionView. Here is document about about Data binding and MVVM, you can refer to it.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.