简体   繁体   English

如何在vb.net中的cellclick事件上的DataGridView中在运行时跟踪对象

[英]How to keep track of Objects at runtime in DataGridView on cellclick event in vb.net

As per my functionality when I click on a cell in datagridview,a dialog opens. 根据我的功能,当我单击datagridview中的单元格时,将打开一个对话框。 I fill all the values in the dialog and store the dialog values into an object dynamically. 我将对话框中的所有值填充,然后将对话框中的值动态存储到对象中。

The same procedure follows for further rows. 对于其他行,遵循相同的过程。

Now how should I persist all the objects values? 现在,我应该如何保留所有对象值?

You can try to save them in a list 您可以尝试将它们保存在列表中

Lets say that your object's name is myObject , with properties, Id, Name and Amount 可以说您的对象名称是myObject,具有属性,Id,名称和数量

Then each time that you save the object you can add it into that list: 然后,每次保存对象时,都可以将其添加到该列表中:

 Dim myList As New List(Of myObject)

' Fill your object with dialog values
dim tempObj as new myObject
tempObj.Id=
tempObj.Name=
tempObj.Amount=


'When you want to save the object'
 myList .Add(tempObj)
'You can do all together and avoid the creation of tempObj:
 'myList .Add(New myObject() With {.Id= 10,.Name="dad",.Amount=122})

You need to provide more info if you want more help. 如果您需要更多帮助,则需要提供更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM