Pages

Tuesday, 12 March 2013

Adding Item in ListView Dynamically Using WPF Window Based

Adding Item in ListView Dynamically Using WPF Window Based

private void button1_Click(object sender, RoutedEventArgs e)
{
    ListView1.Items.Add(textBox1.Text);
}

On button click event handler, we add the content of TextBox to the ListView by calling ListView.Items.Add method. Now if you enter text in the TextBox and click Add Item button, it will add contents of the TextBox to the ListView.

Example:

   

Deleting ListView Items:

The button click event handler looks like following. On this button click,
 we find the index of the selected item and call ListView.Items.RemoveAt method as following.

private void button2_Click(object sender, RoutedEventArgs e)
        {
            ListView1.Items.RemoveAt( ListView1.Items.IndexOf(ListView1.SelectedItem));
        }

Example:
After press Delete Button it Will Delete From ListBox:


No comments:

Post a Comment