Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi there,

 

I need to store all the values of the first row of a datagridview in to an array.

I have tried a lot but havent managed to do this.

 

Can someone help me on the way.

 

Thanks,

Trust the Universe
Posted

I have this....!! :confused:

 

int i = 0;
           string[] cellValues = null;
           // Only take the first row for the search values 

           foreach (DataGridViewCell dataCell in DataGridView1.SelectedRows[0].Cells)
           {
               cellValues[i] = dataCell.Value.ToString();
               i++;
           }

Trust the Universe
Posted

The problem here is that i get an error on the SelectedRows[0].Cells.Count part of the statement.

It says: System.ArgumentoutOfRangeException in the for loop.

Actual value was null. But I am in the grid and there are 3 cells filled with data in the first row...

Trust the Universe
Posted

Hi There,

 

It's not the DataGridView1.SelectedRows[0] property that was needed but the DataGridView1.Rows[0].Cells.Count.

 

That solved this problem on the the next one.

 

Thanks PlausiblyDamp for showing the way.. :)

Trust the Universe
Posted

Hi There,

 

It's not the DataGridView1.SelectedRows[0] property that was needed but the DataGridView1.Rows[0].Cells.Count.

 

That solved this problem on the the next one.

 

Thanks PlausiblyDamp for showing the way.. :)

// Only take the first row for the search values 

string[] cellValues = new string[DataGridView1.Rows[0].Cells.Count];
for (int i = 0; i < this.DataGridView1.Rows[0].Cells.Count; i++)
  {
       cellValues[i] = DataGridView1.Rows[0].Cells[i].Value.ToString();
   }

Trust the Universe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...