Private Sub AddShuntValueToGrid()
Try
Dim rowCnt As Integer = 0
dgvShunts.Rows.Add()
rowCnt = dgvShunts.RowCount
dgvShunts.Rows(rowCnt - 1).Cells(0).Value = True
dgvShunts.Rows(rowCnt - 1).Cells(1).Value = cmbShuntValues.Text & "K"
dgvShunts.Rows(rowCnt - 1).Cells(2).Value = cmbShuntConnections.Text
dgvShunts.Rows(rowCnt - 1).Cells(3).Value = String.Empty
dgvShunts.Rows(rowCnt - 1).Cells(3).ReadOnly = False
dgvShunts.CurrentCell = dgvShunts(3, rowCnt - 1)
Catch ex As Exception
EH.strRetVal = "frmCalibration_SizeChanged() - " & ex.Message & "...Contact Engineering!" & "~E"
End Try
EH.ProcessMessages(Me, sbr, EH.strRetVal)
End Sub
Screenshot.jpg
Public DGSource as New Datatable()
'On The Load for the form
Dim C0 As New DataColumn
With C0
.DataType = GetType(System.Boolean)
.ColumnName = "CHK"
End With
Dim C1 As New DataColumn
With C1
.DataType = GetType(System.String)
.ColumnName = "K Values"
End With
Dim C2 As New DataColumn
With C2
.DataType = GetType(System.String)
.ColumnName = "K Conection"
End With
Dim C3 As New DataColumn
With C3
.DataType = GetType(System.String)
.ColumnName = "K Other Values"
End With
dgvShunts.DataSource = DGSource
dgvShunts.DataBind()
'On Your procedure
Private Sub AddShuntValueToGrid()
Try
Dim RW As DataRow = DGSource.NewRow
With RW
.Item(0) = True
.Item(1) = cmbShuntValues.Text & "K"
.Item(2) = cmbShuntConnections.Text
.Item(3) = Strings.Empty
End With
DGSource.Row.Add(RW)
dgvShunts.DataSource=Nothing
dgvShunts.DataSource = DGSource
dgvShunts.DataBind()
Catch ex As Exception
EH.strRetVal = "frmCalibration_SizeChanged() - " & ex.Message & "...Contact Engineering!" & "~E"
End Try
EH.ProcessMessages(Me, sbr, EH.strRetVal)
Public Class Shunt
Public Property Check As Boolean
Public Property Values As String
...
End Class
Dim shunts As New Collection.Generic.List(Of Shunt)
Dim shunt As Shunt
shunt=New Shunt
shunt.Check=True
shunt.Values="whathever is True"
shunts.add(shunt)
shunt=New Shunt
shunt.Check=False
shunt.Values="whatherver is False"
shunts.add(shunt)
yourGrid.DataSource=shunts
But databinding does only one thing: it requires less code to fill the grid and update the data in the collection. To do that, it also brings it's own overhead and takes control of a few things, which might not be what you want. Private tblShunts As New DataTable
'
'
'
Private Sub Form1_Load()
CreateShuntGrid()
.
.
.
End Sub
'
'
'
Private Sub CreateShuntGrid()
Try
tblShunts.Columns.Add("printed")
tblShunts.Columns.Add("shunt")
tblShunts.Columns.Add("conx")
tblShunts.Columns.Add("output")
dgvShunts.AutoGenerateColumns = False
Catch ex As Exception
EH.strRetVal = "CreateShuntGrid() - " & ex.Message & "...Contact Engineering!" & "~E"
End Try
End Sub
'
'
'
Private Sub AddShuntValueToGrid()
Try
Dim row As DataRow = tblShunts.NewRow
Dim rowCnt As Integer = 0
With row
.Item(0) = True
.Item(1) = cmbShuntValues.Text & "K"
.Item(2) = cmbShuntConnections.Text
.Item(3) = String.Empty
End With
tblShunts.Rows.Add(row)
dgvShunts.DataSource = Nothing
dgvShunts.DataSource = tblShunts
rowCnt = dgvShunts.RowCount
dgvShunts.Rows(rowCnt - 1).Cells(3).ReadOnly = False
dgvShunts.CurrentCell = dgvShunts(3, rowCnt - 1)
Catch ex As Exception
EH.strRetVal = "frmCalibration_SizeChanged() - " & ex.Message & "...Contact Engineering!" & "~E"
End Try
EH.ProcessMessages(Me, sbr, EH.strRetVal)
End Sub
'
'
'
Private Sub cmbShuntValues_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbShuntValues.SelectedIndexChanged
Try
If Not blnLoading Then
If cmbShuntValues.Text.Length > 0 Then
AddShuntValueToGrid()
End If
End If
Catch ex As Exception
EH.strRetVal = "cmbShuntValues_SelectedIndexChanged() - " & ex.Message & "...Contact Engineering!" & "~E"
End Try
EH.ProcessMessages(Me, sbr, EH.strRetVal)
End Sub
Private Sub AddShuntValueToGrid()
Try
Dim rowCnt As Integer = 0
EH.strRetVal = ""
dgvShunts.Rows.Add()
rowCnt = dgvShunts.RowCount
dgvShunts.Rows(rowCnt - 1).Cells(0).Value = True
dgvShunts.Rows(rowCnt - 1).Cells(1).Value = cmbShuntValues.Text & "K"
dgvShunts.Rows(rowCnt - 1).Cells(2).Value = cmbShuntConnections.Text
dgvShunts.Rows(rowCnt - 1).Cells(3).Value = String.Empty
dgvShunts.CurrentCell = dgvShunts(3, rowCnt - 1)
dgvShunts.Focus()
Catch ex As Exception
EH.strRetVal = "AddShuntValueToGrid() - " & ex.Message & "...Contact Engineering!" & "~E"
End Try
EH.ProcessMessages(Me, sbr, EH.strRetVal)
End Sub