Hi,
if you want in windows application try this:
I think it is possible if you play with MouseUp event and Select method.
And although DataGrid control cannot give the selected rows indexes, we can save them to an ArrayList.
For example
Code Block
Private datagrid As DataGrid
Private selectedRows As ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
selectedRows = New ArrayList()
Dim datatable As New DataTable("parameter")
datatable.Columns.Add("col1", GetType(Boolean))
datatable.Columns.Add("col2", GetType(String))
datatable.Rows.Add(False, "bcd")
datatable.Rows.Add(False, "ABC")
datatable.Rows.Add(False, "bcd")
datatable.Rows.Add(False, "ABC")
datatable.Rows.Add(False, "bcd")
datatable.Rows.Add(False, "ABC")
datatable.Rows.Add(False, "bcd")
datatable.Rows.Add(False, "ABC")
datatable.Rows.Add(False, "bcd")
datatable.Rows.Add(False, "ABC")
datagrid = New DataGrid()
datagrid.Width = 400
datagrid.Height = 300
datagrid.DataSource = datatable
Dim boolColumn As New DataGridBoolColumn()
boolColumn.AllowNull = False
boolColumn.Width = 20
boolColumn.MappingName = "col1"
Dim textColumn As New DataGridTextBoxColumn()
textColumn.HeaderText = "col2"
textColumn.MappingName = "col2"
Dim dgt As New DataGridTableStyle()
dgt.MappingName = "parameter"
dgt.GridColumnStyles.Add(boolColumn)
dgt.GridColumnStyles.Add(textColumn)
datagrid.TableStyles.Add(dgt)
Me.Controls.Add(datagrid)
AddHandler datagrid.MouseUp, AddressOf datagrid_MouseUp
End Sub
'ArrayList to save the selected Rows.
Private Sub datagrid_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim hit As DataGrid.HitTestInfo = datagrid.HitTest(e.X, e.Y)
If hit.Column = 0 AndAlso hit.Type = DataGrid.HitTestType.Cell Then
datagrid(hit.Row, hit.Column) = Not CBool(datagrid(hit.Row, hit.Column))
If CBool(datagrid(hit.Row, hit.Column)) Then
'If the checkbox is selected, add the row to ArrayList
selectedRows.Add(hit.Row)
datagrid.[Select](hit.Row)
Else
'If not, remove the row from ArrayList
selectedRows.Remove(hit.Row)
End If
For i As Integer = 0 To selectedRows.Count - 1
'Select all the selected rows
datagrid.[Select](Convert.ToInt32(selectedRows(i)))
Next
End If
End Sub
More info
http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagrid.select.aspx