Windows Develop Bookmark and Share   
 index > Windows Forms General > retrieve text from a datagridview column
 

retrieve text from a datagridview column

Hi,

I want to retrieve the text from a particular column("address") in the current row.
How can this be done?

Thanks in Advance
rowter  Thursday, September 10, 2009 2:42 AM
Hi,

Assuming your grid is called dataGridView1 try,

string

addressValue = dataGridView1.CurrentRow.Cells["Address"].Value.ToString();

Of course in real code you'd need to make sure CurrentRow was not null before you attempted to access it'sCells property, and the above code assumes the name of the column is "Address"... you might need to change that depending on what you named the column.

  • Marked As Answer byrowter Thursday, September 10, 2009 3:40 PM
  •  
Yort  Thursday, September 10, 2009 3:11 AM
Hi,

Assuming your grid is called dataGridView1 try,

string

addressValue = dataGridView1.CurrentRow.Cells["Address"].Value.ToString();

Of course in real code you'd need to make sure CurrentRow was not null before you attempted to access it'sCells property, and the above code assumes the name of the column is "Address"... you might need to change that depending on what you named the column.

  • Marked As Answer byrowter Thursday, September 10, 2009 3:40 PM
  •  
Yort  Thursday, September 10, 2009 3:11 AM

you can used

datagrid[<column number>][<row number>].value

to access particular cell value

Bharath kumar Y.S  Thursday, September 10, 2009 3:17 AM
Thanks that worked
rowter  Thursday, September 10, 2009 3:40 PM

You can use google to search for other answers

Custom Search

More Threads

• C#,javascript, ASP.Net - Avoid the glowing border lines in Media player
• Icon Library
• Calling Controls in Second From
• how to get print out in plotter+C#
• DirectX.AudioVideoPlayback Dispose() method...
• Error: PInvoke item (field,method) must be Static.
• Mdi child also a parent work around
• using member of form 2 in form 1
• Setting DateTimePicker value to null on instantiation of form
• Mark event handlers as [field: NonSerializable]