在DataGridView中使用Rowenter事件时奇怪的Bahavior
我有一个DataGridView,一个与DataGridView和Textbox相同的内容的列表,当我更改行时,文本框的内容会根据我选择的行进行了更改(它们没有通过Databind链接,但我更改了内容手动)。到这里,一切都很好。
现在,我需要,如果修改了文本框的内容,并更改DataGridView中选择的行,然后更改所选行,请检查文本框的内容是否已修改,如果有,则询问我是否想要保存列表中的更改。
对于此任务,我想到了使用DataGridView的Roughenter事件,将文本框的内容与列表的内容进行比较,但是当我在roughenter事件中放置一个消息框时,我遇到了一个困难,询问我是否要为了保存与否,无论我是回答是还是否,datagridview的行都不会更改,我希望它在询问后立即更改行,是否保存了文本框更改,或者是否有另一种方法要检查是否更改与列表的文本框的内容,在更改数据杂志中的行之后,
我将留下所使用的代码的一部分。
private void dgvVisitas_RowEnter(object sender, DataGridViewCellEventArgs e)
{
if (numeroFilaVisitaActual == e.RowIndex)
{
if (txtNotasVisita.Text != listaVisitasPaciente[e.RowIndex].Notas)
{
MessageBox.Show("No es igual"); // If this Message is show, the row don't change
}
}
numeroFilaVisitaActual = e.RowIndex;
}
I have a datagridview, a list with the same content as the datagridview and a textbox, when I change the row, the content of the textbox changes according to the row that I have selected (they are not linked through databind, but I change the content manually). Up to here everything works fine.
Now, I need that, if I modify the content of the textbox, and I change the row selected in the datagridview, before changing the row selected, check if the content of the textbox has been modified, and if it has, ask if I want to save the changes in the list.
For this task, I thought of using the RowEnter event of the datagridview, comparing the content of the textbox with the content of the list, but I ran into a difficulty, when I put a MessageBox inside the rowenter event, to ask if I want to save or not, no matter if I answered yes or no, the row of the datagridview does not change, and I want it to change the row right after asking, whether or not I saved the textbox change, or if there is another way to check if I change the content of the textbox with respect to the list, after changing the row in the datagridview
I leave part of the code that I am using.
private void dgvVisitas_RowEnter(object sender, DataGridViewCellEventArgs e)
{
if (numeroFilaVisitaActual == e.RowIndex)
{
if (txtNotasVisita.Text != listaVisitasPaciente[e.RowIndex].Notas)
{
MessageBox.Show("No es igual"); // If this Message is show, the row don't change
}
}
numeroFilaVisitaActual = e.RowIndex;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论