datagrid - Find specific column and get values to an array in visual C# -


i trying refer specific column of datagrid , values array. don't errors problem zeroth position of array seem have value while other positions null.there 4 records in datagrid. doing wrong

here's code:

   private void button1_click(object sender, eventargs e)      {         string[] arr = new string[10];          datatable getdata = new datatable();         foreach (datagridviewrow row in this.datagridview1.rows)         {             datagridviewcell cell = row.cells[1];              {                 if (cell != null && (cell.value != null))                 {                     (int = 0; < datagridview1.rows.count; i++)                     {                         arr[i] = cell.value.tostring();                     }                 }             }         }          if (arr[0] != null)         {             textbox3.text = arr[0].tostring();//prints value         }         else if (arr[1] != null)//seems null         {             textbox2.text = arr[1].tostring();         }     } 

try this:

private void button1_click(object sender, eventargs e)  {     string[] arr = new string[10];     int =  0;      datatable getdata = new datatable();     foreach (datagridviewrow row in this.datagridview1.rows)     {         datagridviewcell cell = row.cells[1];          {             if (cell != null && (cell.value != null))             {                 arr[i] = cell.value.tostring();             }             i++;         }     } 

hope helps. - corix


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -