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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:11:39+00:00 2026-06-01T18:11:39+00:00

I am designing a winform which have a datagridview. I am assigning a datatable

  • 0

I am designing a winform which have a datagridview.
I am assigning a datatable to that datagridview.

DataTable dt = new DataTable();
dt.Columns.Add("items", typeof(string[]));
dt.Columns.Add("dateSold", typeof(string));

for (int i = 0; i < 6; i++)
{
    dt.Rows.Add(dt.NewRow());
    dt.Rows[i]["items"] = new string[] { "pencil" + i, "sharpner" + i };
    dt.Rows[i]["dateSold"] = "0" + i + "/0" + i + "/0" + i;
}
dataGridView1.DataSource = dt;

Column items is an array of strings. I want to show this array in one coloum of the grid.
But by simply assigning the datatable as the datasource of the datagridview doesn’t help.

  • 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-06-01T18:11:40+00:00Added an answer on June 1, 2026 at 6:11 pm

    The syntax you’re using is a bit strange. There are overloads that would allow you to add a new row and set a value at the same time.

    Also, you can’t have a string array be a field for a cell. Instead of using a DataTable you could create a custom class, and bind a list of them to the DataGridView. This way you could have an underlying field which is an array of strings, and then have a public property that formats them as you desire, and then displays that in the DataGridView.

    Here’s a sample of how to approach this:

    Imports System.ComponentModel
    
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim sales As New BindingList(Of SaleTransaction)
    
            For i As Integer = 1 To 6
                sales.Add(New SaleTransaction(i))
            Next
    
            ' None of this is necessary since the DGV will automatically read the public properties.. '
    
            DataGridView1.AutoGenerateColumns = False
    
            Dim itemsColumn As New DataGridViewTextBoxColumn
    
            itemsColumn.HeaderText = "Items"
            itemsColumn.ValueType = GetType(String)
            itemsColumn.DataPropertyName = "Items"
    
            DataGridView1.Columns.Add(itemsColumn)
    
            Dim dateColumn As New DataGridViewTextBoxColumn
    
            dateColumn.HeaderText = "Date Sold"
            dateColumn.ValueType = GetType(String)
            dateColumn.DataPropertyName = "DateSold"
    
            DataGridView1.Columns.Add(dateColumn)
    
            DataGridView1.DataSource = sales
    
        End Sub
    
        Public Class SaleTransaction
            Private _items As List(Of String)
    
            Public ReadOnly Property Items As String
                Get
                    Return String.Join(", ", _items)
                End Get
            End Property
    
            Public Property DateSold As Date
    
            Public Sub New(ByVal itemNumber As Integer)
                Me._items = New List(Of String) From {"Pencil" & itemNumber, "Sharpner" & itemNumber}
                Me.DateSold = Date.Parse(String.Format("0{0}/0{0}/0{0}", itemNumber))
            End Sub
    
        End Class
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing WinForms application for which I'm now designing new bits in
While designing a new feature for a software application that I'm working on, I
Designing AIR application which has to have server side push or notification, don't know
whilst designing the about page for my new service, i have stumbled across a
When designing a C API for configuring a library/utility, I have a co-worker who
While designing a new WPF application I noticed exceptions not being thrown during data
When designing a form I have the option of putting a close button at
I am currently designing a new .NET application and would like to keep it
I am trying to determine the best approach when designing a new Access based
When designing a web service that will allow the consumer of the service to

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.