且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在字符串变量的datagrid列中存储多个单元格值

更新时间:2023-10-04 12:25:22

我建议回到基础......你必须处理数据,而不是字符串表示!



你需要的只是创建自定义类 [ ^ ],界面 [ ^ ]和自定义类集合 [ ^ ]。



自定义类的定义可能如下所示:

界面:

I'd suggest to get back to basics... You have to work on data, not on its string representation!

All what you need is to create custom class[^], interface[^] and custom class collection[^].

The definition of custom class may look like:
Interface:
Public Interface IMyData
    Property Id As Integer
    Property quantity As Integer
    'and so on...
End Interface





等级:



Class:

Public Class MyData 
        Implements IMyData

    Private id As Integer = 0
    Private quantity As Integer = 0
    Private item  As String = String.Empty
    Private cost  As Integer = 0
    Private idtype As String = String.Empty

    Public Property Id As Integer Implements IMyData
        Get 
            Return id
        End Get
        Set (value As Integer)
            id = value
        End Set 
    End Property

    'and so on...

End Class





收藏类:



Collection Class:

Public Class MyDataCollection 
     Implements Collections.CollectionBase
     'define Add and Remove methods
     'define Item property which returns MyData class

End Class





模块:



Module:

Public Module Module1
'define global variable
Public oMdc As MyDataCollection  = Nothing

End Module





现在,您可以在表单之间共享数据。



Now you can share data between forms.

oMdc = New MyDataCollection
Dim oMd As IMyData = New MyData

With oMd
    .Id = 1
    'other properties
End With
'add custom class to the collection
oMdc.Add(oMd)


'later
DataGridView.DataSource = oMdc





这只是一个想法,而不是完整的解决方案。



It's just an idea, not complete solution.