Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6370617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:57:13+00:00 2026-05-25T00:57:13+00:00

You have a pseudo-table class and a pseudo-row class. The row is somewhat generic

  • 0

You have a pseudo-table class and a pseudo-row class. The row is somewhat generic and has no strongly-typed fields. It follows the typical dictionary interface

Dim age As Object = person("Age") 'accessed via default property Item

vs

Dim age As Integer = person.Age 'an actual property typed as an Integer

What’s the pattern to use so that we can bind our pseudo table and its rows to a grid or combo box?

Dim rs As New clsResultSet(tblPeople)
Dim id As Object   = rs(0)("Id")   '913
Dim name As Object = rs(0)("Name") 'Ted
Dim age As Object  = rs(0)("Age")  '43
Dim occupation As Object = rs(0)("Occupation") 'cab driver

grd.DataSource = rs 'In grid I expect to see Name, Age, Occupation columns

cbo.DataSource    = rs
cbo.DisplayMember = "Name" 'could we do this?
cbo.ValueMember   = "Id"   '...and this?

I read all about IList, IBindingList, BindingSource, etc., tried some things, and I’m still puzzling over how to get this right. Most examples I’ve found expect your record objects to be strongly typed (e.g. person.Age rather than person(“Age”)).

Here are some simple classes to start with:

Public Class clsResultSet 'Like a DataTable
    Inherits List(Of clsRecord)

    Private mdicFields As New Dictionary(Of String, Object)

    Public Sub New(vdt As DataTable) 'Loaded from table
        For Each bdc As DataColumn In vdt.Columns
            Me.mdicFields.Add(bdc.ColumnName, bdc)
        Next
        For Each vdr As DataRow In vdt.Rows
            Me.Add(New clsRecord(vdr, Me))
        Next
    End Sub

    Public ReadOnly Property Fields As Dictionary(Of String, Object)
        Get
            Return Me.mdicFields
        End Get
    End Property
End Class

Public Class clsRecord 'Like a DataRow
    Inherits Dictionary(Of String, Object)
    Private mrs As clsResultSet

    Protected Friend Sub New(vdr As DataRow, vrs As clsResultSet)
        Me.mrs = vrs
        For Each bPair As KeyValuePair(Of String, Object) In vrs.Fields
            Me.Add(bPair.Key, vdr(bPair.Key))
        Next
    End Sub
End Class

This question, as asked, was answered. I reframed it since I didn’t get to the root of my problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:57:14+00:00Added an answer on May 25, 2026 at 12:57 am

    As far as I know there is no way to directly bind to dictionary objects. Here’s a quick workaround for a combobox with a fixed DataSource. Create a new list with the desired properties using Select and anonymous objects (works with Visual Studio 2008 and newer):

    Dim rs As New clsResultSet(tblPeople)
    cbo.DataSource = rs.Select(Function(x) New With {.Name = x("Name"), .Id = x("Id")}).ToList()
    cbo.DisplayMember = "Name"
    cbo.ValueMember   = "Id"
    

    I suppose you could use a similar approach to bind to a DataGridView, but I would recommend using a strongly-typed class instead (a Person class with properties Name, Age, etc.), unless it’s a read-
    only DataGridView that won’t change.

    Edit:

    You might be interested in the Remarks section of the DataGridView.DataSource documentation. Basically the DataSource can be either an IList, IListSource, IBindingList or IBindingListView. DataTable and DataSet classes implement IListSource so it might be worth trying to implement this interface for your own class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
I have a table which has two fields. There can be multiple rows with
I have the following pseudo-SQL schema: table flight id int primary key date timestamp
I have a pseudo random number generator (PRNG) class that I want to unit
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have this table structure <table id=latest class=debt> <thead> <tr> <th width=50>Credor</th> <th width=50>Devedor</th>
I'm trying to have text spans pop up on a hover pseudo-class for different
I have table tab1 (pseudo-structure) tab1 { fname char(20) code int } I have
I have a table that contains computer login and logoff events. Each row is
Here's a pseudo-table: Table: people name : varchar is_married : varchar I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.