Results 1 to 9 of 9

Thread: [RESOLVED] Datagrid View Current Row

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Resolved [RESOLVED] Datagrid View Current Row

    i want to set first row as current row in datagrid view.
    in vb we can it as

    Code:
    grid.Row=1
    Thanks in advance

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Datagrid View Current Row

    To set the CurrentRow you have to set the CurrentCell to a cell in the desired row. The first row has an index or 0, as with all .NET collections.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Datagrid View Current Row

    You want to select the first row in the datagrid view?

    If it's that you just do this:
    vb Code:
    1. grid.Rows(0).Selected = True

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Datagrid View Current Row

    mickey tats working

    i want to display the records of first row to the corresponding textboxes , in which the data is selecting by the id (id is in 1st column) while loading the grid itself

  5. #5
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Datagrid View Current Row

    You have a datagrid and textbox's and you want when the user select a row in the datagrid the values in the text box's reflect the values in the row?

    I it's data you must set the text box's databindings...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Datagrid View Current Row

    NO mickey now its coming without seting databinding to the text boxes while clicking on the corresponding rows. what i want is display the the data of the first row while form loading

  7. #7
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Datagrid View Current Row

    You can assign the values directly.... If you have all the values in the datagridview just do something like:

    VB.NET Code:
    1. TextBox1.Text = grid.Rows(0).Cells("ColName1").Value.ToString
    2. TextBox2.Text = grid.Rows(0).Cells("ColName2").Value.ToString
    3. ...

    When the form loads? It takes so much time?

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Datagrid View Current Row

    at the start of the program itself the form is loading. i have created function for loading the contents while clicking on the grid. the same function is loading while the form is loading. There is variable for loading the id while clicking the grid
    Code:
    EditPatientId = CInt(grdPatients.Item(0, grdPatients.CurrentCell.RowIndex).Value.ToString())
    ..
    the same variable suppose to load the first row's ID

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Datagrid View Current Row

    it is solved by setting current cell in the form load and afte that i just call the function in which it is taking current cell's Vallue

    Code:
    dataGrid.CurrentCell = dataGrid(0, 0)
               Call funcGridOnClick()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width