Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Referencing the selected ro in a DataGrid

Referencing the selected ro in a DataGrid

Scheduled Pinned Locked Moved Visual Basic
questioncss
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dptalt
    wrote on last edited by
    #1

    On my windows form I have a textbox and a datagrid. As I navigate through the grid's data how can I display the selected row of the first column in the textbox? Thanks

    G A 2 Replies Last reply
    0
    • D dptalt

      On my windows form I have a textbox and a datagrid. As I navigate through the grid's data how can I display the selected row of the first column in the textbox? Thanks

      G Offline
      G Offline
      Guerven
      wrote on last edited by
      #2

      There are many ways to extract information, first you need to identify the index of the record you want to extract. We can use the ME.Databindingcontext( datasource ).position to identify the current row. Normally we assign a table to a datagrid's datasource, but here we will use the Table.Defaultview. SO given TBL1 as your datatable Datagrid.datasource = TBL1.Defaultview then we can use Me.BindingContext(TBL1.DefaultView).Position() to indentify the current row, this should work even it you change the sort field of the datagrid. I think thats it. Dim ID As String 'use the this event handle Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged Dim x As Int16 'Datagrid1.datsource = tbl1.Defaultview ' instead of Datagrid1.datsource = tbl1 ' you must explicitly point to the tables defaultview 'Get the position of the Table's Defaultview x = Me.BindingContext(TBL1.DefaultView).Position() 'use x to identify you row textbox1.text = TBL1.DefaultView(x)("fieldname") End Sub Marvin N. Guerrero - Taje Kage_bunshinNunJutsU Marvin N. Guerrero - Taje Kage_bunshinNunJutsU

      1 Reply Last reply
      0
      • D dptalt

        On my windows form I have a textbox and a datagrid. As I navigate through the grid's data how can I display the selected row of the first column in the textbox? Thanks

        A Offline
        A Offline
        aseef
        wrote on last edited by
        #3

        hi, try this TxtboxName.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex(), 0).ToString() Live Life King Size Asif

        D 1 Reply Last reply
        0
        • A aseef

          hi, try this TxtboxName.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex(), 0).ToString() Live Life King Size Asif

          D Offline
          D Offline
          dptalt
          wrote on last edited by
          #4

          That will not work if the datasource is a sorted view.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups