使用DGV创建新表单:在运行时传递值 [英] Creating New Form with DGV : passing the value during runtime

查看:54
本文介绍了使用DGV创建新表单:在运行时传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我创建了一个带有DataGridView的ModbusPollFormFull()表单. DataGridView将每秒持续更新数据.我创建了一个"NEW FORM"菜单项/按钮,以创建确切的表单.我希望每当创建这些新表单时,它们也能够更新DGV中的数据,但具有自己的控件.
我的问题是,这些新表单在运行时根本没有显示任何数据.我该如何解决这个问题?

谢谢

Hi,
I have created a ModbusPollFormFull() form with DataGridView in it. The DataGridView will continuously update the data every second. I put a "NEW FORM" menu item/button in order to create the exact form. I want whenever i created those new forms,they have the ability to update the data in DGV as well but having its own control.
My problem is, those new forms did not showed me any data at all during the runtime. How can i solves this problem?

Thank you

Private Sub NewMenuItem_File_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click

        Start += 1
            For i As Integer = 0 To Start
            NewForm = New ModbusPollFormFull()
            NewForm.Text = "ModbusPoll:" & i
       Next





我已经有一个用于读取硬件的不同类,它是"Modbus"类来帮助我填充数据.
我使用MainForm()调用Modbus()类函数(也使用PollFunction()方法和计时器),并创建另一种形式ModBusPollFormFull()以通过DataGridView1(地址","ID", 值"列).

我有两种形式(MainForm和ModbusPollFormFull()).
ModbusPollFormFull()由DataGridView1和两个标签组成(轮询计数标签和NoConnection标签).
MainForm上有一个三个按钮. (新建表单")按钮可创建ModbusPollFormFull()的多个实例.
单击开始"按钮开始填充ModbusPollFormFull()中的DataGridView1数据,单击停止"按钮停止填充ModbusPollFormFull()中的DataGridView1数据.

在运行时(经过时间)填充了DataGridView1,显然,DataGridView1中的值每秒都在变化.
单击(开始")按钮时,轮询计数"标签显示计数器.单击("Stop")按钮时,将显示NoConnection标签.

当我单击(新建表单")按钮时,我希望新的ModbusPollFormFull()将能够从零开始轮询计数
并且新ModbusPollFormFull()中的DataGridView1将能够像现有ModbusPollFormFull()中那样填充数据.






i already have a different class for reading the hardware, which is "Modbus" class to help me populate the data.
I use the MainForm() to call the Modbus()class functions (using PollFunction() method and timer elapsed as well) and i create another form,ModBusPollFormFull()to read the data through DataGridView1 ("Address","ID","Value" columns).

I have two forms (MainForm and ModbusPollFormFull()).
ModbusPollFormFull() consists of DataGridView1, and and two label (poll count label and NoConnection label).
There is a three button on MainForm. ("New Form" )button to create multiple instance of ModbusPollFormFull().
("Start") button to start populate DataGridView1 data in ModbusPollFormFull() and ("Stop") button to stop populate DataGridView1 data in ModbusPollFormFull().

The DataGridView1 is populate during runtime(timer-elapsed) and obviously the values in DataGridView1 are changing every second.
Poll Count label shows the counter when the ("Start") button is clicked. NoConnection label will be visible when the ("Stop") button is clicked.

When i clicked ("New Form") button, i want the new ModbusPollFormFull() will be able to start the Poll Count from zero
and the DataGridView1 in the new ModbusPollFormFull() will be able to populate data as in the existing ModbusPollFormFull().


Private Sub NewForm_File_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewForm.Click
 
Dim nf As Form
 
For i As Integer = 0 To Start

nf = New ModbusPollFormFull()
nf.Text = "ModbusPollForm:" & i
nf.Name = "ModbusPollFormFull" & i
 

For j As Integer = 20 To Inc 'Positioning the new form
nf.Left = j
Next
 
'i dont know what im should do starts from here. 


Next 
 
nf.Show()
 

 
Private Sub PollFunction()
 
'Update GUI:(delegates function)
DoGUIClear()
pollCount += 1
ModbusPollformFull.mpfDoGUIStatus("Poll count:" & pollCount.ToString())

'Create array to accept read values:
Dim values(CInt(QuantityCB.Text)) As Short
Dim pollStart As UShort
Dim pollLength As UShort
 
If AddressCB.Text <> "" Then
pollStart = Convert.ToUInt16(AddressCB.Text)
Else
pollStart = 0
End If
 
If QuantityCB.Text <> "" Then
pollLength = Convert.ToUInt16(QuantityCB.Text)
Else
pollLength = 20
End If
 

'Read Registers and display data in desired format:
Try
Modbus.ReadHoldingRegister_Fc3((Convert.ToByte(SlaveIDCB.Text)), pollStart, pollLength, values)
 
Catch ex As Exception
DoGUIStatus("Error in modbus read : " & ex.Message)
End Try
 

Dim itemString As String
Dim itemString2 As String
Dim itemString3 As String
 
Select Case dataType
 
Case "Hexadecimal"
For i As Integer = 0 To pollLength - 1
itemString = Convert.ToString(pollStart + i)
itemString2 = Convert.ToString(pollStart + i + 1)
itemString3 = values(i).ToString("X")
DoGUIUpdate(itemString, itemString2, itemString3) 'Delegates functions

Next i
 
Case "Decimal"
For i As Integer = 0 To pollLength - 1
 
itemString = Convert.ToString(pollStart + i)
itemString2 = Convert.ToString(pollStart + i + 1)
itemString3 = values(i).ToString("")
DoGUIUpdate(itemString, itemString2, itemString3)

 
Next i
End Select
 
End Sub



你能帮我吗?



Can you help me?

推荐答案

好吧,除了Text之外,没有任何迹象表明可以将任何数据传递给表单.
您可以向表单类添加任何类型的只写或读写属性,以传递任何数据.您还可以向表单类添加另一个构造函数,并使用参数来传递数据来代替您显示的代码片段.

—SA
Well, there is nothing showing that you pass any data to the form, except Text.

You can add any kind of write-only or read-write properties to your form class, to pass any data. You can also add another constructor to the form class, with parameters used to pass data in place of the code fragment you show.

—SA


这篇关于使用DGV创建新表单:在运行时传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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