Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using a generic.dictionary as the source for a datagridview

Posted on 2007-03-29
2
Medium Priority
?
2,310 Views
Last Modified: 2011-10-03
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).datapropertyName = "Display"
      datagridview1.columns(1).datapropertyName = "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
0
Comment
Question by:syscomdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 41

Accepted Solution

by:
graye earned 2000 total points
ID: 18827564
You are correct... the Generic.Dictionary class does not support the IList (or any of the other supported interfaces) that would qualify it for being a DataSource.

I'd recommend you use a BindingList instead of a Dictionary.   There is a pretty good example that is almost an exact match to your example at the MSDN web site at:

http://msdn2.microsoft.com/en-us/library/ms132679.aspx
0
 

Author Comment

by:syscomdev
ID: 18832699
The one thing that I would lose would be the ability to find a value by a key, i.e.
tests("example1").datatype = 5.

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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question