Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i used below coding to store data from listitems to array.From array to datagridview.
when i click button data added successfully into datagridview from array., but if i click again the same data appear two times into datagridview., [two times same data]. how to avoid this
 
private void button1_Click(object sender, EventArgs e)
      {
          try
          {
              foreach (ListItem li2 in ch11.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
 
              foreach (ListItem li2 in ch1.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
 
              foreach (ListItem li2 in ch2.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
 
              foreach (ListItem li2 in ch3.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
              foreach (ListItem li2 in ch4.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
              foreach (ListItem li2 in ch5.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
 
              foreach (ListItem li2 in ch8.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
 
              foreach (ListItem li2 in ch6.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
 
              foreach (ListItem li2 in ch7.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
              foreach (ListItem li2 in ch9.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
              foreach (ListItem li2 in ch10.CheckedItems)
              {
                  total_items[items] = li2.Text;
                  items++;
              }
 
              dataGridView1.Rows.Clear();
              dataGridView1.Columns.Clear();
              dataGridView1.Columns.Add("Items", "Choosed Items");
 
              try
              {
                  for (int j = 0; j < items; j++)
                  {
                      dataGridView1.Rows.Add(total_items[j].ToString());
                  }
              }
              catch (Exception err)
              {
                  MessageBox.Show(err.Message);
              }
 
           }
 
          catch (SqlException err)
          {
              MessageBox.Show(err.Message);
          }
      }
Posted 14-Nov-12 20:52pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

myGrid.Children.Clear() will remove all child controls nested in the grid. myGrid.RowDefinitions.Clear() will remove all row definitions. myGrid.ColumnDefinitions.Clear() will remove all column definitions.
  Permalink  
Comments
Umapathi K at 15-Nov-12 3:04am
   
its windows application., unable to get extension of .children and .rowdefinitions and.columndefinitions

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 265
1 _Amy 235
2 Peter Leow 205
3 Andreas Gieriet 180
4 Dave Kreskowiak 130
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,712


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100