如何从datagridview获取随机值 [英] How to get random value from datagridview

查看:74
本文介绍了如何从datagridview获取随机值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谦虚..请帮助我.
我有一个标签,计时器和datagridview.当timer_Tick时,它会随机从datagrid获取值.
怎么做.很抱歉我的英语不好,因为我是印度尼西亚人..

With humble..please help me.
I have a label, timers and datagridview. When the is timer_Tick, it''s take value from datagrid by random.
How to do that. I''m sorry that my poor english, cause i''m an Indonesian..

推荐答案

您应该查看随机函数http://msdn.microsoft.com/en-us/library/system.random.aspx [ ^ ]

暗兰特(Dim rand)作为新的Random()

现在,您应该选择两个值,一个用于列,一个用于行,然后从datagridview中获取该值.

要从单元格获取值,请使用以下代码:
http://msdn.microsoft.com/en-us/library/ms158656.aspx [ ^ ]
You should look into the Random function http://msdn.microsoft.com/en-us/library/system.random.aspx[^]

Dim rand as new Random()

Now you should pick two values one for column and one for row, and then get the value from the datagridview.

To get the values from the cell use this:
http://msdn.microsoft.com/en-us/library/ms158656.aspx[^]


请参阅我对这个问题的评论,我建议在其中使用单独的线程而不是计时器.这更加直接和安全.使用计时器,您会遇到很多问题.没有什么可以保证您的计时器事件处理程序总是在下一个事件发生之前及时执行,对吗?那你会怎么做?

但是最主要的是:我不想根据定期重复的获取价值的过程向您提供任何建议,因为如果这样做似乎没有任何意义.这被称为轮询",并且总是很糟糕,就像"拉技术"一样.如果用户界面中没有任何变化,为什么还要获得新的价值?您不应该这样做,除非您解释了一些合理而奇怪的理由.合理的UI始终基于来自UI控件的事件.因此,您只需处理UI控件的一些事件,这些事件应触发数据中的所有更新. (一个这样的事件System.Windows.Forms.DataGridView.CellEndEdit; http://msdn.microsoft .com/en-us/library/system.windows.forms.datagridview.cellendedit.aspx [
请参阅:
http://en.wikipedia.org/wiki/Pull_technology [ http://en.wikipedia.org/wiki/Server-push [
Please see my comments to the question where I suggested to use a separate thread instead of timer. This is much more straightforward and safe. With timers, you can get too many problems. Nothing can guarantee that your timer event handler always executes in time, before next event happens, right? And what would you do?

But the main thing is: I don''t want to advise you anything based on regular repeated process of getting values, because if does not seem to make any sense. This is called "polling" and is always bad, as the "pull technology". If nothing changes in the UI, why would you get a new value? You should not do it, unless you explain some good and weird reason for that. A reasonable UI is always based on event coming from the UI control. For that reason, you simply handle some events of the UI control, and these events should trigger all updates in data. (One such event it System.Windows.Forms.DataGridView.CellEndEdit; http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellendedit.aspx[^]; the only problem is that you ignored my question about exact type and did not confirm that you want to use this or some other control with some other UI library.) There are a number of exclusion, but this is when you model some "natural" process, or interact with other source of data synchronous relative to your application.

Please see:
http://en.wikipedia.org/wiki/Pull_technology[^],
http://en.wikipedia.org/wiki/Server-push[^].

As we don''t know the motivation of the behavior you described, that''s all, for now.

—SA


这篇关于如何从datagridview获取随机值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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