简体   繁体   中英

How to see DataGridView changes without changing row

I have a DataGridView with a few DataGridViewComboBoxColumn's. The columns have their DataSource set so that they will display certain values to choose from, however the DataGridView itself does not have its DataSource set to anything. I manually load/save values from it.

The problem: When I change one of the combobox values, I am not seeing the change until I move to another row.

More background info: The primary purpose of the app is to move data from one table to another. In one column you choose the source field of a table, and in the next column you choose the destination field in another table. One feature of the app is that when you click on the row header cell, it will display a list of distinct values from the source field you've selected in that row. However when updating the source field, I cannot get the right results by clicking the row header cell until after I leave the row first.

The question: What is the simplest way to get my changes to take effect immediately instead of having to leave the row first? I implemented something to accomplish this for a checkbox column once but the solution I came up with doesn't work for a combobox column. I'd like something that works for everything.

Thanks!

Edit: If you hapepen to be reading this and thinking to yourself "This is a bad question", would you mind letting me know why? I really don't mind if you downvote it... I would just like to understand whether the problem is something to do with this being a 'bad SO question', or do you think I'm asking to do something that you believe isn't smart and is a bad practice to follow.

I infer that you want the value to be committed as soon as its selected, so maybe this might help in achieving that. subscribe to CurrentCellDirtyStateChanged and see if it does the thing which you intend.

void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
{
    if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

尝试使用以下功能:

dataGridView.RefreshEdit();

Are you searching for the CellValidated event? You can manually save the data in this event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM