How do I add a data entry control inside of the ListView.

Ronald Rex 1,666 Reputation points
2023-03-24T19:30:03.5933333+00:00

I am trying to add a data entry control called Entry Cell inside of a ListView so that the user can enter data that I can save to the Database. I get the error... A value of type 'EntryCell' cannot be added to a collection or dictionary of type 'IList`1'.

 <ListView ItemsSource="{Binding sfDataGridModelCollection}">
                            <ListView.ItemTemplate>
                                <DataTemplate>

                                    <ViewCell>
                                        <HorizontalStackLayout>
 <EntryCell Label="Name"Placeholder="Enter name" Text="{Binding LocalName}" />
                                          
                                        </HorizontalStackLayout>
                                    </ViewCell>

                                </DataTemplate>
                            </ListView.ItemTemplate>
 </ListView>
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,903 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,286 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
766 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,661 Reputation points Microsoft Vendor
    2023-03-27T03:16:44.8766667+00:00

    Hello,

    If you want to use EntryCell in the listview, you need to remove ViewCell, add EntryCell directly. You cannot nested use ViewCell and EntryCell.

      <ListView ItemsSource="{Binding sfDataGridModelCollection}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <EntryCell Label="Name" Placeholder="Enter name" Text="{Binding LocalName}" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
    

    Here is a document 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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Lloyd Sheen 1,386 Reputation points
    2023-03-24T21:54:02.53+00:00

    The DataTemplate will have a grid as its top level a grid. Then define grid columns for each property of the object you are binding to. Then each control can be whatever you want ex. for a property that cannot be editted a Lable and for others an Entry or a ComboBox depending on what the property is.