怎么在winform得到datagrid里的checkbox选中的行的数据
在datagrid里加了checkbox然后要得到这行的数据,把这些数据放进int1和int2两个参数里。我该怎么做?
我得到选中行的语句是:Dim rows as datarow() = ds1.tables( "table1 ").select( "Bool = 1 ")
请问我接下来该怎么写啊?ds1是我dataset的名字。。
[解决办法]
5.80 How can I get a CheckBox column in a DataGrid to react to the first click?
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q945q
[VB.Net}
Private myCheckBoxCol As Integer = 9 'my checkbox column
Private Sub DataGrid2_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles DataGrid2.MouseUp
Dim hti As DataGrid.HitTestInfo = Me.dataGrid2.HitTest(e.X, e.Y)
Try
If hti.Type = DataGrid.HitTestType.Cell AndAlso hti.Column = myCheckBoxCol Then
Me.dataGrid2(hti.Row, hti.Column) = Not CBool(Me.dataGrid2(hti.Row, hti.Column))
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub 'dataGrid2_MouseUp
其他参考:
5.33 How do I get the row and column of the current cell in my datagrid?
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q788q
5.27 How can I get the selected text in an active gridcell?
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q827q
5.15 How can I put a checkbox in a column of my DataGrid?
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q754q
[解决办法]
For i = 0 To Me.DataGridView1.Rows.Count - 1
checkCell = CType(DataGridView1.Rows.Item(i).Cells(0), DataGridViewCheckBoxCell)
isChecked = CType(checkCell.Value, [Boolean])
If isChecked = True Then
int1=
int2=
......
end if