GetValueByName

In beta1 there was a fantastic way of getting values out of a gridview using:

Gridview1.DataKeys(Gridview1.SelectedIndex).GetValueByName("Name").ToString

In beta2 this has been removed - how do I achieve the same results? I used this alot and will have to change a lot of code, especially if I have to use the reader class.

Vince

[336 byte] By [vruttan] at [2008-2-18]
# 1
Try instead next (lang=C#):

Gridview1.DataKeys[Gridview1.SelectedIndex]["Name"].ToString()
ploc at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
I think there are some even easier ways to get at specific cells or the Current (selected) cell.

Basically you want to think about getting a cell object as a result of a Row and Collumn coordinate. E.g.



Dim dgv As New DataGridView

Dim cell As DataGridViewCell

cell = dgv.Rows(0).Cells(1)

Here a few more examples building on the same concept, but varying how to access rows and cells


cell = dgv.Rows(dgv.CurrentRow.Index).Cells("name")

cell = dgv.CurrentRow.Cells("name")

cell = dgv.CurrentCell

I hope that helps.

Paul

PaulYuk_MS at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Top notch contribution.

congrats.

Walter

Renate at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...