I have a DataGridView
populated with a DataTable
.
I added a CheckBoxColumn
to select some rows.
My Goal is to show only selected rows into another DataGridView
I tryed to accomplish this using Select
and adding results to a new DataTable
but Select
doesn't work because CheckBoxColumn
is missing.
Here's the code I used to fill 1st DataGridView
and add a CheckBoxColumn
:
Dim chk0 As New DataGridViewCheckBoxColumn()
With chk0
.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader
.HeaderText = "Sel"
.Name = "Sel"
End With
With Me.DataGridView1
.Columns.Clear()
.DataSource = DT_Events
.Columns.Insert(0, chk0)
.Columns("Event").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
End With
Then, after checking some rows, I tryed to show the selected ones into another DataGridView
:
Using DT_Checked As DataTable = CType(Me.DataGridView1.DataSource, DataTable).Select("Sel = 1").CopyToDataTable
If DT_Checked.Rows.Count > 0 Then
With Me.DataGridView2
.Visible = True
.DataSource = DT_Checked
End With
Else
MsgBox("No rows to show", MsgBoxStyle.Critical, "Error")
End If
End Using
I tryed this code without Select
and it doesn't show me CheckBoxColumn
.
How can I fix?
How can I do it otherwise?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…