datagrid current record

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jose

    #1

    datagrid current record

    How obtain the current record in the datagrid? The idea is doubleclick and
    show another form with this current recor of my datagrid.

    Thanks a lot


  • tomb

    #2
    Re: datagrid current record

    Jose wrote:
    [color=blue]
    >How obtain the current record in the datagrid? The idea is doubleclick and
    >show another form with this current recor of my datagrid.
    >
    >Thanks a lot
    >
    >
    >
    >[/color]
    Use the underlying data source instead.

    Tom

    Comment

    • Alan

      #3
      Re: datagrid current record

      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_Cur rentCellChanged (ByVal sender As Object,
      ByVal e As System.EventArg s) Handles dgvBranches.Cur rentCellChanged

      Try
      'Determine which row and column selected and
      'display contents of cells in proper text boxes.
      CurrentRow = dgvBranches.Cur rentCell.RowNum ber
      CurrentColumn = dgvBranches.Cur rentCell.Column Number
      ShowTheCells()

      Catch ex As Exception
      LogErrors(ex, " In frmMain_dgvBran ches_CurrentCel lChanged")
      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.Sel ect(CurrentRow)
      txtState.Charac terCasing = CharacterCasing .Upper
      txtBranchNum.Te xt = Trim(dgvBranche s.Item(CurrentR ow, 0))
      txtBranchName.T ext =
      Trim(StrConv(dg vBranches.Item( CurrentRow, 1), VbStrConv.Prope rCase))
      txtRegCode.Text = Trim(dgvBranche s.Item(CurrentR ow, 2))
      txtOrder.Text = Trim(dgvBranche s.Item(CurrentR ow, 3))
      txtRegName.Text = RegionName(dgvB ranches.Item(Cu rrentRow,
      2))

      If dgvBranches.Ite m(CurrentRow, 4) = "True" Then
      cbxActive.Check ed = True
      ElseIf dgvBranches.Ite m(CurrentRow, 4) = "False" Then
      cbxActive.Check ed = False
      End If

      Dim i As Integer

      For i = 0 To myDataSet.Table s("MySQL Branches").Rows .Count
      - 1

      If dgvBranches.Ite m(CurrentRow, 0) =
      myDataSet.Table s("MySQL Branches").Rows (i).Item(0) Then
      txtStreet.Text = StrConv(myDataS et.Tables("MySQ L
      Branches").Rows (i).Item(2), VbStrConv.Prope rCase)
      txtZip.Text = myDataSet.Table s("MySQL
      Branches").Rows (i).Item(3)
      txtCity.Text = StrConv(myDataS et.Tables("MySQ L
      Branches").Rows (i).Item(4), VbStrConv.Prope rCase)
      txtState.Text = StrConv(myDataS et.Tables("MySQ L
      Branches").Rows (i).Item(5), VbStrConv.Upper Case)
      txtPhone.Text = myDataSet.Table s("MySQL
      Branches").Rows (i).Item(6)
      txtFax.Text = myDataSet.Table s("MySQL
      Branches").Rows (i).Item(7)
      txtConFirst.Tex t = StrConv(myDataS et.Tables("MySQ L
      Branches").Rows (i).Item(8), VbStrConv.Prope rCase)
      txtConLast.Text = StrConv(myDataS et.Tables("MySQ L
      Branches").Rows (i).Item(9), VbStrConv.Prope rCase)
      txtBranchEmail. Text =
      StrConv(myDataS et.Tables("MySQ L Branches").Rows (i).Item(10),
      VbStrConv.Upper Case)
      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

      Comment

      Working...