Solved

Using a generic.dictionary as the source for a datagridview

Posted on 2007-03-29
2
2,299 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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