PC Review


Reply
Thread Tools Rate Thread

DataGridView in c# - Getting cell value

 
 
dushkin
Guest
Posts: n/a
 
      5th Jan 2012
Hello.

I am trying to work with DataGridView object.

I put it on a form, launcehd it and added a new row with 3 cells.
Then I edited the three cells.

So it looks like this:

+-------------+-------------+-------------+-------------+
| | HD1 | HD2 | HD3 |
+-------------+-------------+-------------+-------------+
| | Val1 | Val2 | Val3 |
+-------------+-------------+-------------+-------------+

Now I am strugging to get the values from the grid. I tried this code
(among many others...)

foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCellCollection cells = row.Cells;
Console.WriteLine("Cells Count = {0}", cells.Count);
Console.WriteLine("Cells[0] = {0}", cells[0].ToString());
Console.WriteLine("Cells[0].value = {0}", cells[0].Value);
}


But the value I get is null !

The other output is

Cells Count = 3
Cells[0] = DataGridViewTextBoxCell { ColumnIndex=0, RowIndex=0 }

What is wrong here?

I am editing the grid directly in the cell (inplace editing). Do I
need to do an extra operation before I can try to retrieve back the
text?

Thanks!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:45 AM.