Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference cell in datagridview

Status
Not open for further replies.

pwomack

Technical User
Apr 16, 2005
121
US
Using VB2008 in a Windows application.

Currently this is what I use to reference a value in a cell in a datagridview:

Code:
sOrderNo = Me.dgvOrders.CurrentRow.Cells(15).Value

Is it possible to reference the cell value by using the column name? Such as,

Code:
sOrderNo = Me.dgvOrders.CurrentRow.Cells("OrderNo").Value
 
When in you code window, if you type:

Me.dgvOrders.CurrentRow.Cells(

intellisense should show a small yellowish-colored box (default). This box should have a little arrow set in it and it should say something like 1 of 3.

This means there are three overloads for that method... In the case of DataGridView.Current.Cells, there are three overloads: 1) no value given, 2) Index Number of the cell you want, 3) Text Name of the cell you want.

So...in short...yes.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Your second example is how you do it. I use VB2005 but I don't think that it changes for 2008.

I find it much easier to reference the column names than the column numbers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top