Results 1 to 2 of 2

Thread: SendKeys and Datagrid Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    72

    SendKeys and Datagrid Problem

    Hi,

    I have a datagrid that I am saving to a database.

    If i am currently in a cell and have changed the value of it, but have not exited the cell or pressed enter the change is not reflected in the database.

    I think what I have to do is either mimic the Enter key or ALT key command on the activecell in the datagrid, I have tried using

    Code:
    SendKeys.Send("{ALT}")
    This doesnt work, does anyone know how to use sendkeys on a datagrid so that I can mimic pressing enter or ALT?

    Thanks.

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

    Re: SendKeys and Datagrid Problem

    I assume that you are actually using a DataGridView. It contains no controls by default, with each cell simply having its contents rendered directly to the grid itself. When you start editing a cell, a control of the appropriate type is created or an existing one used if there is one, the Value property of the cell is assigned to the appropriate property of the control (e.g. Text of a TextBox) and the control is embedded in the cell. When you navigate away from the cell the value from the control is copied back to the cell and the control removed.

    What you should be doing when you want to save your data is first calling the Validate method of the form. If that returns True then you call the EndEdit method of your BindingSource, which you should be using to bind to the grid, and then you can safely save the data. That will raise all the right events to end the editing session and transfer the data from the editing control, through the grid and into the underlying data source.

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