帮助:需要使DataGrid行“刷新”内容 [英] Help: Need to cause DataGrid row to "flush" contents

查看:79
本文介绍了帮助:需要使DataGrid行“刷新”内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要一些帮助,以编程方式在DataGrid中导致一行刷新其内容为其绑定数据的内容(在Visual Studio 6中使用Windows窗体

with C#)。


我的问题是我想从菜单命令

向用户发送更新数据正在编辑DataGrid。对于

示例和正常做法而言,这是不寻常的,因为DataGrid的单元格仍然具有焦点。在我可以找到的所有示例中,用户通常在表单上按下

按钮。这种做法导致DataGrid失去焦点,并且
自动将当前行的内容刷新到其绑定数据成员。

但是当我尝试执行更新时用户仍在继续编辑

数据连续,DataSet更新没有该特定行。


我试图通过简单设置<的焦点来解决这个问题br />
表单上的另一个控件(例如btnSave.Focus()),希望

DataGrid失去焦点并将其行内容刷新到DataSet,但是

这被证明是无法解释的无效。这行仍然没有刷新。我不知道Focus()调用是否需要在事件链最终确定之前通过

迭代一次。


我真的很想以正确的方式做到这一点。我不想在更新之前使用类似

之类的黑客选择另一行,但是我无法在

DataGrid中找到任何方法来强制其内容刷新其绑定数据。

是否有人对此有明确的程序。也许我只是想念

这里一个明显或众所周知的方法?

解决方案

Junkguy,


我认为最好的方法是在执行操作之前在数据网格上调用EndEdit方法

。这将允许您结束当前编辑的
并在完成后更新基础数据源。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- nick(dot)paldino = at = exisconsulting< dot> com

Junkguy <菊***** @ columbus.rr.com>在留言中写道

news:ju *************************** @ news-server-fe-01。 columbus.rr.com ...


我需要一些帮助,以编程方式使DataGrid中的行刷新其内容到其绑定数据(在Visual Studio中) 6使用Windows窗体
和C#)。

我的问题是我想在用户编辑DataGrid时从菜单命令
向数据库发送更新。对于
示例和正常实践而言,这是不寻常的,因为DataGrid的单元格仍然具有焦点。在我可以找到的所有示例中,用户通常按下表单上的
按钮。这种做法导致DataGrid失去焦点并自动将当前行的内容刷新到其绑定的数据成员。
但是当我尝试在用户仍在进行编辑时执行更新时
连续的数据,DataSet更新没有那个特定的行。

我试图通过简单地设置窗体上另一个控件的焦点来避免这个问题(例如btnSave.Focus()) ,希望
DataGrid失去焦点并将其行内容刷新到DataSet,但是这被证明是无法解释的无效。这行仍然没有被刷新。我不知道Focus()调用是否需要在事件链最终确定之前迭代一次。

我真的想以正确的方式执行此操作。我不想在更新之前使用类似
选择另一行的黑客,但我无法在DataGrid中找到任何方法来强制其内容刷新到其绑定数据。是否有人对此有明确的程序。也许我只是缺少这里一个明显或众所周知的方法?



junkguy,我所做的是以下内容:


this.grdWorksheet.CurrentCell = new DataGridCell(0,0);

this.grdWorksheet.CurrentCell = new DataGridCell(0,1);

this.grdWorksheet.CurrentCell = new DataGridCell(0,0);


这样,焦点就会变为数据网格中的现有单元格。并且

即使新编辑的单元格在同一行,更改也会更新。


Erald Kulk


在文章< Og ************** @ TK2MSFTNGP11.phx.gbl>,

" ; Nicholas Paldino [.NET / C#MVP]" < ni ************** @ exisconsulting.com>

写道:

我认为最好的方法这样做是在执行操作之前在数据网格上调用EndEdit方法。这将允许你结束当前的编辑,并在完成后更新基础数据源。

希望这会有所帮助。



谢谢Nicholas,


希望它会有所帮助,但显然当在数据表上调用

AcceptChanges()时,EndEdit已被调用。我确实试图获得CurrencyManager并调用其EndCurrentEdit()调用

。它仍然是b $ b拒绝工作。像往常一样,有一些深奥的事情发生在

真的真的让事情结束了,没有人抓住了这个bug因为

不管怎么说,因为离开了

DataGrid。


- 积木


-

Junkguy



I need some help programmatically causing a row in a DataGrid to "flush"
its contents to its bound data (in Visual Studio 6 using Windows Forms
with C#).

My issue is I want to send an update to a database from a menu command
while the user is editing a DataGrid. This is unusual in regard to
examples and normal practice in that the cell of the DataGrid still has
the focus. In all examples I can find, the user normally presses a
button on a Form. This practice causes the DataGrid to lose focus and
automatically flush the current row''s contents to its bound data member.
But when I attempt to perform an update while the user is STILL editing
data in a row, the DataSet updates WITHOUT that particular row.

I attempted to circumvent this problem by simply setting the focus of
another control on the form (e.g. btnSave.Focus()), hoping that the
DataGrid would lose focus and flush its row contents to the DataSet, but
this proved to be inexplicably ineffective. The row was still not
flushed. I don''t know if a Focus() call needs to iterate once through
the event chain before it finalizes or what.

I really want to do this the right way. I don''t want to use a hack like
selecting another row before updating, but I can''t find any method in
DataGrid that will force its contents to flush to its bound data. Does
anyone have the definitive procedure on this. Perhaps I''m simply missing
an obvious or well known method here?

解决方案

Junkguy,

I think that the best way to do this would be to call the EndEdit method
on the data grid before you perform the action. This will allow you to end
the current edit and should update the underlying data source when done.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Junkguy" <ju*****@columbus.rr.com> wrote in message
news:ju***************************@news-server-fe-01.columbus.rr.com...


I need some help programmatically causing a row in a DataGrid to "flush"
its contents to its bound data (in Visual Studio 6 using Windows Forms
with C#).

My issue is I want to send an update to a database from a menu command
while the user is editing a DataGrid. This is unusual in regard to
examples and normal practice in that the cell of the DataGrid still has
the focus. In all examples I can find, the user normally presses a
button on a Form. This practice causes the DataGrid to lose focus and
automatically flush the current row''s contents to its bound data member.
But when I attempt to perform an update while the user is STILL editing
data in a row, the DataSet updates WITHOUT that particular row.

I attempted to circumvent this problem by simply setting the focus of
another control on the form (e.g. btnSave.Focus()), hoping that the
DataGrid would lose focus and flush its row contents to the DataSet, but
this proved to be inexplicably ineffective. The row was still not
flushed. I don''t know if a Focus() call needs to iterate once through
the event chain before it finalizes or what.

I really want to do this the right way. I don''t want to use a hack like
selecting another row before updating, but I can''t find any method in
DataGrid that will force its contents to flush to its bound data. Does
anyone have the definitive procedure on this. Perhaps I''m simply missing
an obvious or well known method here?



junkguy, what I do is the following:

this.grdWorksheet.CurrentCell = new DataGridCell(0,0);
this.grdWorksheet.CurrentCell = new DataGridCell(0,1);
this.grdWorksheet.CurrentCell = new DataGridCell(0,0);

this way, the focus changes to an existing cell in the datagrid. and
even if the new edited cell is in the same row, the changes will be
updated.

Erald Kulk


In article <Og**************@TK2MSFTNGP11.phx.gbl>,
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>
wrote:

I think that the best way to do this would be to call the EndEdit method
on the data grid before you perform the action. This will allow you to end
the current edit and should update the underlying data source when done.

Hope this helps.


Thanks Nicholas,

Wish it would help, but apparently EndEdit is already being called when
AcceptChanges() is called on the data table. I literally tried getting
the CurrencyManager and calling its EndCurrentEdit() call. It still
refused to work. As usual, there is some esoteric thing that happens to
really really make the thing end and nobody has caught the bug because
the whateveritiscall is getting coincidentally invoked by leaving the
DataGrid.

--Junkguy

--
Junkguy


这篇关于帮助:需要使DataGrid行“刷新”内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆