H
Hexman
Hello All,
I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it.
-------------------------------
1) Add a cb to the dgv, iterate thru the dgv and update the bound fields if the cb has been checked. Then do the update and accept changes. How do I
access the cb and its checked status? How to iterate thru dgv?
Dim cbSelCol As New DataGridViewCheckBoxColumn
dgv1.Columns.Insert(0, cbSelCol)
With cbSelCol
.HeaderText = "Select"
.Name = "RecSel"
.DisplayIndex = 0
.Frozen = True
End With
For Each dgv1????row in dgv1.rows
if dgv1????row("RecSel").Checked then
...do some update process....
end if
Try
daEN.Update(dtEN)
Catch ex As Exception
'An exception occurred
End Try
Next
dtEN.AcceptChanges()
-------------------------------
2) Create an alias boolean field in the SELECT statement when creating the datatable. Then test the checkbox and update as applicable. How do I
change the cell style to checkbox (of "RecSel")? How to test if checked?
ENQrySel = "SELECT True as RecSel, ENDate, ... "
"FROM ... WHERE ... ORDER BY ..."
daEN.Fill(dtEN)
dgv1.DataSource = dtEN
DIM drEN as DataRow
For Each drEN in dtEN.Rows
If drEN("RecSel") ???Selected??? then
...do some update process....
End If
Try
daEN.Update(dtEN)
Catch ex As Exception
'An exception occurred
End Try
Next
dtEN.AcceptChanges()
Which way is best/doable? Other suggestions?
Thanks,
Hexman
I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it.
-------------------------------
1) Add a cb to the dgv, iterate thru the dgv and update the bound fields if the cb has been checked. Then do the update and accept changes. How do I
access the cb and its checked status? How to iterate thru dgv?
Dim cbSelCol As New DataGridViewCheckBoxColumn
dgv1.Columns.Insert(0, cbSelCol)
With cbSelCol
.HeaderText = "Select"
.Name = "RecSel"
.DisplayIndex = 0
.Frozen = True
End With
For Each dgv1????row in dgv1.rows
if dgv1????row("RecSel").Checked then
...do some update process....
end if
Try
daEN.Update(dtEN)
Catch ex As Exception
'An exception occurred
End Try
Next
dtEN.AcceptChanges()
-------------------------------
2) Create an alias boolean field in the SELECT statement when creating the datatable. Then test the checkbox and update as applicable. How do I
change the cell style to checkbox (of "RecSel")? How to test if checked?
ENQrySel = "SELECT True as RecSel, ENDate, ... "
"FROM ... WHERE ... ORDER BY ..."
daEN.Fill(dtEN)
dgv1.DataSource = dtEN
DIM drEN as DataRow
For Each drEN in dtEN.Rows
If drEN("RecSel") ???Selected??? then
...do some update process....
End If
Try
daEN.Update(dtEN)
Catch ex As Exception
'An exception occurred
End Try
Next
dtEN.AcceptChanges()
Which way is best/doable? Other suggestions?
Thanks,
Hexman