Is there a bug w/ the DataGridView?

Hi all,

I'm using the following code:

ForEach SelectedRowAs DataGridViewRowIn grd.SelectedRows

SelectedRow.Cells("IsTrue").Value =True

Next

Ex. of my problem:

Row|IsTrue

1 |0

2 |0

Using the above code will only make Row 1 True, and leave Row 2 as False. If I just Select Row 1, then the code above sets Row 1 to True just fine.

The ONLY way to make it work is to hard-code the following:

grd.Item("IsTrue", 0).Value =True

grd.Item("IsTrue", 1).Value =True

grd.Item("IsTrue", 2).Value =True

Any variable in the row index of grd.Item produces the same problem. It MUST be hard-coded.

Anyone know why?

- Thanks ahead of time.

[2004 byte] By [Denvas] at [2007-12-26]
# 1

Public Class Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

For Each SelectedRow As DataGridViewRow In Me.DataGridView1.SelectedRows

SelectedRow.Cells("Column2").Value = True

Next

End Sub

End Class

just tried your code with a checkbox column as column2, and it works properly,

selected row is a row selected by clicking on row header, so to select multiple rows, i had to hold control and click on the multiple row headers(on the left). and it worked. , what are you setting to true actually?

hrubesh at 2007-9-4 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2

Hi,

Thanks for the response. The column I'm setting to true is a check box column. And what's weird is that it won't check off the last box, until you select another row (after the code has run) - then it just checks itself automatically. So the value is set to True (F8'ing it), but it doesn't reflect on the form till the second step of clicking on another row.

Denvas at 2007-9-4 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3
post the code plz
hrubesh at 2007-9-4 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...