Vb.net datgridview控件 [英] Vb.net datgridview control

查看:82
本文介绍了Vb.net datgridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在每个datagridview行上添加Timer控件并在记录状态时重置计时器
update?

How to add Timer control on each datagridview row and reset timer when record status
update?

推荐答案

可能是System.Windows.Forms.Timer.它是Component,但不是Control.

这个不正确的问题背后有一个真正的问题.例如,我从未理解过为什么Designer会向表单添加非可视组件.我了解,有些工具中有很多工具旨在给商务人士留下深刻印象,并产生一种幻想,即无需编程"就可以创建应用程序.为此,设计了这种行为,以便项目立即开始工作".一个简单的事实,对于任何严肃的项目,这更多的是分心而不是收益.

不,您并不是真的需要它.从本质上讲,计时器不会添加"到控件中.计时器是应用程序全局对象,即使其变量在某些上下文中是局部的.您可以创建任意数量的计时器.只需定义一个计时器变量,正确地对其进行初始化,然后使用计时器回调委托或事件即可.

哦,有三种类型的计时器:System.Timers.TimerSystem.Threading.TimerSystem.Windows.Forms.Timer.这是添加到表单中的最后一个;这是最糟糕的,非常不准确的.这样做的目的是取悦商务人士,并产生一种幻觉,即无需编程"即可创建应用程序.它的优点是不需要使用Invoke.其他计时器需要它.

您不能从计时器回调委托实例或事件处理程序中调用与UI相关的任何内容.相反,您需要使用System.Windows.Threading.DispatcherInvokeBeginInvoke方法(对于Forms或WPF)或System.Windows.Forms.Control(仅对于Forms).

在我过去的答案中,您将找到有关其工作原理的详细说明和代码示例:
Control.Invoke()与Control.BeginInvoke() [ ^ ],
Treeview Scanner和MD5的问题 [如何获取keydown事件在vb.net中的不同线程上操作 [启用禁用+多线程后控件事件不会触发 [ ^ ].

—SA
Probably you mean System.Windows.Forms.Timer. It is a Component, but not Control.

There is a real problem behind this incorrect question. I never understood why Designer adds non-visual components to the form, for example. I understand, there is a lot in some tools more designed to impress business people and create an illusion that applications are created "without programming". For this purpose, such behavior is designed so the project starts to "work" immediately. The simple fact that for any serious project this is more of a distraction than a benefit.

No, you did not really need it. By its nature, a timer does not "added" to a control. The timer is application-global object, even if its variable is local to some context. You can create any number of timers. Just define a timer variable, initialize it properly and use timer callback delegate or event.

Oh, there are three types of timers: System.Timers.Timer, System.Threading.Timer and System.Windows.Forms.Timer. It''s the last one which is added to a form; and this is the worst one, extremely inaccurate. It''s purpose it to please business people and create an illusion that applications are created "without programming". Its benefit it that it does not need to use Invoke. To other timers require it.

You cannot call anything related to UI from the timers callback delegate instance or event handler. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

My final recommendation is: most likely, you don''t need timers at all. In most cases, you can use threads instead. In fact, writing periodic processing with threads is easier then with timers and the result is much safer.

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA


这篇关于Vb.net datgridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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