Results 1 to 3 of 3

Thread: [RESOLVED] Selecting a Row in a Datagrid

  1. #1

    Thread Starter
    Hyperactive Member Quasar6's Avatar
    Join Date
    Mar 2008
    Location
    Sol 3
    Posts
    325

    Resolved [RESOLVED] Selecting a Row in a Datagrid

    Hi everyone.

    I have a datagridview, which is bound to a Microsoft Access table.

    To update parts of the database, I have been changing a the data-bound Text property of a text box, and then calling the following three lines:
    Code:
    BindingSource.EndEdit();
    TableAdapter.Update(DataSet);
    
    TableAdapter.Fill(DataSet.Table);
    This works fine, but I have encountered a problem: everytime I call these lines, the currently selected row (only one row may be selected at a time) resets to the first item in the table.

    I was planning to store the current row's index in a temp variable, call those lines, then call a method which will re-select the row at that index.

    I haven't been able to find a method to achieve this. Dioes someone know how can I select a specific row in a data-bound datagridview?

    If there's a better way to do this, by all means let me know.

    Thanks,
    Qu.

    EDIT: Sorry, nearly forgot: I'm using MS Access 2003, Visual C# Express and an OleDb Connection.
    Last edited by Quasar6; Jul 9th, 2008 at 08:26 PM.
    "Why do all my attempts at science end with me getting punched by batman?" xkcd.

    |Pong||
    Sorry for not posting more often.

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

    Re: Selecting a Row in a Datagrid

    Why are you calling Fill? Are there autogenerated values you need to get? This is easier with other databases that support multiple SQL statements in the one command. You can simply get the BindingSource's Position property before the Fill and then reset it afterwards.

  3. #3

    Thread Starter
    Hyperactive Member Quasar6's Avatar
    Join Date
    Mar 2008
    Location
    Sol 3
    Posts
    325

    Re: Selecting a Row in a Datagrid

    Hmmm... that's a good point. I probably don't need to be calling Fill as much as I am.

    A few people will be working on the database at a time, so I was using Fill to try to keep it up to date on everyones screen. Perhaps a simple refresh button would be a better way to go.

    My ignorance is starting to show. Thanks for the help Jmc.
    "Why do all my attempts at science end with me getting punched by batman?" xkcd.

    |Pong||
    Sorry for not posting more often.

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