syscomdev
asked on
Using a generic.dictionary as the source for a datagridview
vs2005 vb.net
Public Class test
Private displayValue As String
Private dbType As Integer
Property Display() As String
Get
Return displayValue
End Get
Set(ByVal value As String)
displayValue = value
End Set
End Property
Property DataType() As Integer
Get
Return dbType
End Get
Set(ByVal value As Integer)
dbType = value
End Set
End Property
Public Sub New(ByVal dspl As String, ByVal dt As Integer)
Display = dspl
DataType = dt
End Sub
End Class
I have a generic.dictionary [Dim tests As New Generic.Dictionary(Of String, test)] which i would like to bind to a datagridview
if it were a collection (which contained a series of class 'test'), I would :
datagridview1.datasource = collName
datagridview1.columns(0).d atapropert yName = "Display"
datagridview1.columns(1).d atapropert yName = "DataType"
However I don't appear to be able to do the same thing with a dictionary. So far I found that you need to do:
datagridview1.datasource = tests.values
But I do not know how to bind the specific value of the class for the dictionary.
Thank you
Public Class test
Private displayValue As String
Private dbType As Integer
Property Display() As String
Get
Return displayValue
End Get
Set(ByVal value As String)
displayValue = value
End Set
End Property
Property DataType() As Integer
Get
Return dbType
End Get
Set(ByVal value As Integer)
dbType = value
End Set
End Property
Public Sub New(ByVal dspl As String, ByVal dt As Integer)
Display = dspl
DataType = dt
End Sub
End Class
I have a generic.dictionary [Dim tests As New Generic.Dictionary(Of String, test)] which i would like to bind to a datagridview
if it were a collection (which contained a series of class 'test'), I would :
datagridview1.datasource = collName
datagridview1.columns(0).d
datagridview1.columns(1).d
However I don't appear to be able to do the same thing with a dictionary. So far I found that you need to do:
datagridview1.datasource = tests.values
But I do not know how to bind the specific value of the class for the dictionary.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tests("example1").datatype
The item method in the BindingList is only by numeric.
So is my basic choice which is more important? To be able to gather the data by key or to have it displayed?
I know I could have a simple data construct for the pairing, but was hoping to get around it.
Thank you for the example and any other assistance.