Click here to Skip to main content
15,886,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to add a row into data grid view from another window text box.
How can to do it?

If anyone can help me, thanks.

This is my grid view code

<ListView  Name="ListView1" Margin="6,6,783,145">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Icon" Width="75" DisplayMemberBinding="{Binding Path=Icon}"/>
                                <GridViewColumn Header="Position" Width="75"/>
                                <GridViewColumn Header="Name" Width="75"/>
                                <GridViewColumn Header="Gender" Width="75"/>
                                <GridViewColumn Header="Status" Width="75"/>
                                <GridViewColumn Header="Client ID" Width="75"/>
                            </GridView>
                        </ListView.View>
                    </ListView>
Posted
Updated 9-Apr-11 2:41am
v2
Comments
Dalek Dave 9-Apr-11 8:41am    
Edited for Grammar and Readability

In order to add rows to a list view in WPF you'd rather want to bind the ItemsSource property of the ListView to a collection.

Further you will be able to add items to that collection not just from actual ListView UI element, but also from any code behind (2-Way binding will assure you that the items in the UI will get updated).

XML
<ListView  Name="ListView1" ItemsSource="{Binding YourCollectionName}">
     <ListView.View>
         <GridView>
             <GridViewColumn Header="Icon" Width="75" DisplayMemberBinding="{Binding Path=Icon}"/>
                 <GridViewColumn Header="Position" Width="75"/>
                 <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
          </GridView>
     </ListView.View>
</ListView>


Adding items from another window's textbox into your ListView will be easily then: you will need to pass your collection object to the second window and manually add items to it.
WPF will take care in updating the UI on the first window.

For details check this: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1[^]
Regards
 
Share this answer
 
v2
Comments
Dalek Dave 9-Apr-11 8:42am    
Good Answer.
Add row in DataGrid dynamically
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900