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

  • Home
  • SEARCH
  • 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 901331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:32:22+00:00 2026-05-15T15:32:22+00:00

In a Windows Form application, I’m trying to create a DataGridView with two columns:

  • 0

In a Windows Form application, I’m trying to create a DataGridView with two columns: one for the key given by an XML element and one for the value of said XML element. This is my code so far:

        this.myData = new DataGridView();
        ((System.ComponentModel.ISupportInitialize)(myData)).BeginInit();

        myData.Location = new System.Drawing.Point(12, 42);
        myData.Name = "myData";
        myData.Size = new System.Drawing.Size(1060, 585);
        myData.TabIndex = 32;

        foreach (XElement xElem in xInfoItems)
        {
            numItems++;
        }

        myData.Columns.Add(new DataGridViewTextBoxColumn());
        myData.Columns.Add(new DataGridViewTextBoxColumn());
        myData.Columns[0].Name = "Key";
        myData.Columns[0].DataPropertyName = "key";
        myData.Columns[1].Name = "Value";
        myData.Columns[1].DataPropertyName = "value";

        List<myRow> data = new List<myRow>();


        foreach (XElement xElem in xInfoItems)
        {
            data.Add(new myRow(xElem.Attribute("key").Value, xElem.Value));
        }

        myData.DataSource = data;

        myData.Refresh();

        this.PerformLayout();

I have confirmed that all of the information in data is being loaded via foreach, so that part is working. My problem is that the grid displays, but nothing shows up on the grid. What am I doing wrong? I’m not very good with this data type so I apologize if it’s something obvious.

UPDATE

I figured out that I hadn’t set myData up properly in the Design view. After adding the myRow class, it worked perfectly. Thanks for the 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-05-15T15:32:23+00:00Added an answer on May 15, 2026 at 3:32 pm

    The problem may lie in your myRow class. When I was trying to reproduce your code, I first defined “key” and “value” as public fields of the myRow class as so:

    public class myRow {
      public string key;
      public string value;
    
      public myRow( string Key, string Value )
      {
         key = Key;
         value = Value;
      }
    
    }
    

    This caused the bound rows to show up but the text was not in the cells. When I changed both of them to properties, the binding worked much better:

    public class myRow{
      private string _key;
      public string key
      {
         get
         {
            return _key;
         }
      }
    
      private string _value;
      public string value
      {
         get
         {
            return _value;
         }
      }
    
      public myRow( string Key, string Value )
      {
         _key = Key;
         _value = Value;
      }
    

    }

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

Sidebar

Related Questions

I've got a Windows Forms application with two ListBox controls on the same form.
I am trying to design a windows form application. Now I have written an
I have a windows form application that uses a Shared class to house all
We are creating a Windows Form application (C# or VB.NET) that needs to reference
I have been developing a C# windows form application in XP. It all works
I am working on a windows form application. How do i use the find
What tools are useful for automating clicking through a windows form application? Is this
I cannot figure out how to make a C# Windows Form application write to
I'm using VS2008 C# Express and the Northwind database on a Windows Form application.
Is it possible to download a file from a website in Windows Application form

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.