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. DataGrid Current Row and Field

DataGrid Current Row and Field

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 4 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.
  • N Offline
    N Offline
    New_Coder
    wrote on last edited by
    #1

    How do I get the contents of the current field and row from a datagrid? I have set up the code to run when I click on a record in the datagrid and this works until you sort the datagrid by clicking on the column headers. dim test as string test = TestGrid.CurrentRowIndex COMPANY.Text = CODE_DataSet.Tables(CODE_TABLE).Rows(test).Item(0) Any Idesas? :confused:

    D F 2 Replies Last reply
    0
    • N New_Coder

      How do I get the contents of the current field and row from a datagrid? I have set up the code to run when I click on a record in the datagrid and this works until you sort the datagrid by clicking on the column headers. dim test as string test = TestGrid.CurrentRowIndex COMPANY.Text = CODE_DataSet.Tables(CODE_TABLE).Rows(test).Item(0) Any Idesas? :confused:

      D Offline
      D Offline
      Dean_SF
      wrote on last edited by
      #2

      What's happening is the currency manager for the datagrid is no longer pointing to the correct row after you perform a sort. Here's a good description of the problem and a potential solution: http://weblogs.asp.net/dmarsh/archive/2003/01/22/646.aspx[^]

      1 Reply Last reply
      0
      • N New_Coder

        How do I get the contents of the current field and row from a datagrid? I have set up the code to run when I click on a record in the datagrid and this works until you sort the datagrid by clicking on the column headers. dim test as string test = TestGrid.CurrentRowIndex COMPANY.Text = CODE_DataSet.Tables(CODE_TABLE).Rows(test).Item(0) Any Idesas? :confused:

        F Offline
        F Offline
        Felipe Dalorzo
        wrote on last edited by
        #3

        There is an ItemCommand event that fires when you click something in the datagrid one of the arguments for that event is DataGridCommandEventArgs let's call it "e" myItemCommand (object sender, DataGridCommandEventArgs e ) { e.Item.DataItem[0]; /*This a DataRowViewRow*/ } That is how you access a row in a datagrid. Please let me know if I missunderstood your question or there's anything else I can help you with. Greetings, Felipe

        N 1 Reply Last reply
        0
        • F Felipe Dalorzo

          There is an ItemCommand event that fires when you click something in the datagrid one of the arguments for that event is DataGridCommandEventArgs let's call it "e" myItemCommand (object sender, DataGridCommandEventArgs e ) { e.Item.DataItem[0]; /*This a DataRowViewRow*/ } That is how you access a row in a datagrid. Please let me know if I missunderstood your question or there's anything else I can help you with. Greetings, Felipe

          N Offline
          N Offline
          New_Coder
          wrote on last edited by
          #4

          OK I think I have got what I am looking for with: Dim MyCell As DataGridCell Dim MyRow As Integer Dim MyCol As Integer Dim MyData As String MyCell = TestGrid.CurrentCell MyRow = (MyCell.RowNumber) MyCol = (MyCell.ColumnNumber) MyData = CODE_DataSet.Tables(CODE_TABLE).Rows(MyRow).Item(MyCol) COMPANY.Text =MyData This will work as long as there is data in the cell I clicked on. How do I test for NULL? What variable type do I need to set MyData so I dont get a compiler error "Cast from type DBNull to type String in not valid"

          A 1 Reply Last reply
          0
          • N New_Coder

            OK I think I have got what I am looking for with: Dim MyCell As DataGridCell Dim MyRow As Integer Dim MyCol As Integer Dim MyData As String MyCell = TestGrid.CurrentCell MyRow = (MyCell.RowNumber) MyCol = (MyCell.ColumnNumber) MyData = CODE_DataSet.Tables(CODE_TABLE).Rows(MyRow).Item(MyCol) COMPANY.Text =MyData This will work as long as there is data in the cell I clicked on. How do I test for NULL? What variable type do I need to set MyData so I dont get a compiler error "Cast from type DBNull to type String in not valid"

            A Offline
            A Offline
            alien viper
            wrote on last edited by
            #5

            IF IsDBNull(MyData) Then COMPANY.Text="" Else COMPANY.Text=MyData End IF !alien!

            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