简体   繁体   English

如何在不更改行的情况下查看DataGridView更改

[英]How to see DataGridView changes without changing row

I have a DataGridView with a few DataGridViewComboBoxColumn's. 我有一个带有一些DataGridViewComboBoxColumn的DataGridView。 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. 列的DataSource设置为显示某些值可供选择,但DataGridView本身没有将DataSource设置为任何值。 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. 订阅CurrentCellDirtyStateChanged并查看它是否符合您的意图。

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

尝试使用以下功能:

dataGridView.RefreshEdit();

Are you searching for the CellValidated event? 您在搜索CellValidated活动吗? You can manually save the data in this event. 您可以在此事件中手动保存数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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