For starters, you need an easy way to reference what is currently
selected on the datagrid control. Start with something like this:
==============================================================
Private Sub dgvBranches_CurrentCellChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles dgvBranches.CurrentCellChanged
Try
'Determine which row and column selected and
'display contents of cells in proper text boxes.
CurrentRow = dgvBranches.CurrentCell.RowNumber
CurrentColumn = dgvBranches.CurrentCell.ColumnNumber
ShowTheCells()
Catch ex As Exception
LogErrors(ex, " In frmMain_dgvBranches_CurrentCellChanged")
End Try
End Sub
===============================================================
Once you have that settled then you can do things like passing values
into text boxes and such. There is a lot of formatting in this example
since I wanted to make sure that everything looked good and would save
in a consisten format in the database. Here is an example:
===============================================================
Private Sub ShowTheCells()
'Use the cells from the selected row to display in the proper
text boxes
Try
dgvBranches.Select(CurrentRow)
txtState.CharacterCasing = CharacterCasing.Upper
txtBranchNum.Text = Trim(dgvBranches.Item(CurrentRow, 0))
txtBranchName.Text =
Trim(StrConv(dgvBranches.Item(CurrentRow, 1), VbStrConv.ProperCase))
txtRegCode.Text = Trim(dgvBranches.Item(CurrentRow, 2))
txtOrder.Text = Trim(dgvBranches.Item(CurrentRow, 3))
txtRegName.Text = RegionName(dgvBranches.Item(CurrentRow,
2))
If dgvBranches.Item(CurrentRow, 4) = "True" Then
cbxActive.Checked = True
ElseIf dgvBranches.Item(CurrentRow, 4) = "False" Then
cbxActive.Checked = False
End If
Dim i As Integer
For i = 0 To myDataSet.Tables("MySQL Branches").Rows.Count
- 1
If dgvBranches.Item(CurrentRow, 0) =
myDataSet.Tables("MySQL Branches").Rows(i).Item(0) Then
txtStreet.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(2), VbStrConv.ProperCase)
txtZip.Text = myDataSet.Tables("MySQL
Branches").Rows(i).Item(3)
txtCity.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(4), VbStrConv.ProperCase)
txtState.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(5), VbStrConv.UpperCase)
txtPhone.Text = myDataSet.Tables("MySQL
Branches").Rows(i).Item(6)
txtFax.Text = myDataSet.Tables("MySQL
Branches").Rows(i).Item(7)
txtConFirst.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(8), VbStrConv.ProperCase)
txtConLast.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(9), VbStrConv.ProperCase)
txtBranchEmail.Text =
StrConv(myDataSet.Tables("MySQL Branches").Rows(i).Item(10),
VbStrConv.UpperCase)
End If
Next
Catch ex As Exception
LogErrors(ex, " In ShowTheCells()")
End Try
End Sub
================================================================
"tomb" does have a good point about using the underlying data though.
I think you would have to use the currency manager to accomplish that
one. Hope this helps.
Alan