Dynamic binding of gridview – List

Dynamic binding of grid view.

This is how it looks

It has a grid which displays first name and last name 2 textboxes are there which helps the user to fill the First name and Last name.

 public List<Person> listPerson = new List<Person>();

We ‘ve created an instance of list.Here We use this list to save the class “Person”


  public class Person
            public string Name
            public string LastName

We need to create 2 columns and name its headers and bind these columns with the data from the User.In the Xaml we need to bring modifications as shown below.

 <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" Width="100 ">
                        <GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=LastName}" Width="100 ">

When we click on the button we need to fill the datagrid with the list
Button Click

private void button_Click(object sender, RoutedEventArgs e)
            Person p = new Person();        
            p.Name = txtName.Text;
            p.LastName = txtLastName.Text;
            ListView1.ItemsSource = listPerson;

This is how the final UI looks like

HappyCoding ! 😉


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: