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 5968625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:07:00+00:00 2026-05-22T20:07:00+00:00

At runtime, I have a collection of rows ( Row class). Each of them

  • 0

At runtime, I have a collection of rows (Row class). Each of them consist of column values, represented by instances of a ColumnValue class. The name of the columns are determined at runtime, and are in a separate columns descriptor collection (Column class).

I want to create a DataGridView that displays all Row instances. Of course, the DataGridView‘s columns shall be exactly those specified by the Column instances in the containing collection.

But since DataGridView‘s columns can fetch their values from a list item’s public properties only, and I cannot easily define such a property at runtime, I cannot use DataGridView to display the tabular data.

Correct?

Consider these VB classes for example:

' Classes for table structure representation
Public Class TColumn ' describes my columns
  Public Name As String
  Public Index As Integer

  Public Sub New(ByVal AName As String)
    Name = AName
  End Sub

End Class

Public Class TTable ' describes a table
  Public Name As String
  Public Columns As Collection

  Public Sub New(ByVal AName As String)
    Name = AName
    Columns = New Collection
  End Sub
End Class

' Classes for table data 

Public Class TRow ' Container for one row's column values
  Public ColumnValues As Collection
  Public Sub New()
    MyBase.New()
    ColumnValues = New Collection()
  End Sub
End Class

Public Class TTableData ' Container for a table's rows
  Public Table As TTable
  Public Rows As Collection
  Public Sub New(ByVal ATable As TTable)
    MyBase.New()
    Table = ATable
    Rows = New Collection()
  End Sub
End Class

And this main form code:

Public Class Form1

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim T As TTable
    Dim TD As TTableData
    Dim CV As Collection
    T = New TTable("Sample")
    T.Columns.Add(New TColumn("Column1"))
    T.Columns.Add(New TColumn("Column2"))

    TD = New TTableData(T)
    CV = New Collection
    CV.Add("Row1Col1")
    CV.Add("Row1Col2")
    TD.Rows.Add(CV)

    CV = New Collection
    CV.Add("Row2Col1")
    CV.Add("Row2Col2")
    TD.Rows.Add(CV)

    ' Question: How can I create a DataGridView that displays this:
    ' 
    '     Column1   Column2
    '     Row1Col1  Row1Col2
    '     Row2Col1  Row2Col1
    ' 
    ' WHILE the Columns collection contents are dynamic, i.e. determined at runtime, not at compile- or design-time?
  End Sub
End Class

I wonder what DataGridViewColumn.DataPropertyName value I would specify for example when defining (at runtime) Column1‘s DataGridView column???

Generally asking: Is it true that DataGridView always wants to fetch the data from object instances with public properties, and those define the column structure and especially values? I cannot display stuff that does not have public properties at all?

  • 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-22T20:07:01+00:00Added an answer on May 22, 2026 at 8:07 pm

    You should override the CellFormatting event of DataGridView and set e.Value to table(e.RowIndex)(e.ColumnIndex).

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

Sidebar

Related Questions

I have a column 'name' in Database which has values as 'john,smith'. I'm passing
I have a collection of objects, each of which holds a set of name-value
I have an application which displays a collection of objects in rows, one object
Suppose I have a custom collection class that provides some internal thread synchronization. For
I have a one column grid, with rows of varying heights in a WPF
I am performing serialization using System.Runtime.Serialization.Formatters.Binary.BinaryFormatter . I have a collection which wraps a
How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and
Why does it make sense to have Runtime Exceptions UnChecked (as opposed to if
in runtime i will have a dynamic dictionary object return to me e.g var
I searched for an implementation of std::map runtime ordering and have found this solution:

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.