为什么 Invalidate() 应该在控件外部调用才可以工作?

发布于 2024-09-11 08:00:17 字数 618 浏览 5 评论 0原文

我正在使用C# + winforms来开发软件。
我有一个包含多个DataGridView的UserControl,

datagridview1.datasource = from p in dc.doctor select p;

我使用linq to sql用dataSource填充dataGridView,因为我需要刷新数据源来更新记录,所以我创建一个新的dataContext并再次分配数据源。

datagridview1.datasource = from p in dc.doctor select p;  

起初我发现,虽然我重置了数据源,但datagridview仍然无法刷新,有人告诉我应该调用datagridview上的invalidate函数,我尝试了一下。在某种程度上,它是有效的。 但是如果我在 UserControl 的类中调用 Invalidate,它将不起作用。
如果我在 UserControl 的类上创建一个公共函数,然后使用 userControl.refreshRecord() 调用它,那么它就可以工作。

有人能指出我错过了什么吗?当有人调用invalidate时,什么时候才能真正起作用?
提前致谢 !

I am using C# + winforms to develop software.
I have a UserControl which contains several DataGridView

datagridview1.datasource = from p in dc.doctor select p;

I use linq to sql to populate the dataGridView with dataSource, because I need to refresh the datasource to update the records, so I create a new dataContext and assign the datasource again.

datagridview1.datasource = from p in dc.doctor select p;  

At first I found, although I reset the datasource, the datagridview still can not get refreshed, someone tell me that I should call the invalidate function on datagridview, I tried. To a certain extent, it works.
But If I called the Invalidate inside the UserControl's class, it won't work.
If I create a public function on the UserControl's class, then call it with userControl.refreshRecord(), Then it works.

Can someone point me what am I missed ? When someone call invalidate, when will it really work?
Thanks in advance !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请恋爱 2024-09-18 08:00:17

当控件完成所有其他事情(例如数据加载)时,工作无效......

Invalidate work when the control finish all other things like data loading ...

对你而言 2024-09-18 08:00:17

调用 dgv.Invalidate() 方法对于数据网格视图。

Call dgv.Invalidate() method for datagridview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文