Results 1 to 2 of 2

Thread: Datagridview, get the text from the first cell of the selected row

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Datagridview, get the text from the first cell of the selected row

    Hi all, after some searching around the msdn im no closer to an answer so time to ask you guys for some help.

    I have a data grid view and i want to show the text from the first column of the selected row (regardless of what cell in that row is selected) in a text box.

    So for example in this picture:


    The 1st column of the selected rows text is 'California' so that should be sent to the textbox.

    Any helps much appreciated, Thanks.

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

    Re: Datagridview, get the text from the first cell of the selected row

    There's a difference between "selected" and "current" in a DataGridView. "Selected" means highlighted and you can, depending on the circumstances, have multiple cells or rows selected at the same time. "Current" means containing the caret, and only one cell and row can contain the caret at a time. The grid's CurrentRow property will return a DataGridViewRow, obviously containing the current row. As with all rows, that has a Cells collection, which you can index by column name or ordinal.
    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

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