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 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

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try getting Whitelisted. From the rate-limiting documentation: Whitelisting Some applications… May 16, 2026 at 2:07 pm
  • Editorial Team
    Editorial Team added an answer There is no per-application limit so to say. The amount… May 16, 2026 at 2:07 pm
  • Editorial Team
    Editorial Team added an answer Here's the walkthrough: Walkthrough: Downloading Assemblies on Demand with the… May 16, 2026 at 2:07 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

HI I need to embed two web browsers in one form of a windows
net windows form application. I have a combo box and a text box and
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 a Windows form application that has a child form that pops up
I have Windows Form application and a label which is databound based on a
I developing windows form application in c#.net. Sometimes my program throw an error, windows
I have an Windows Form application that supplies the User Name, Domain, and Password
I have a Windows Form application built on a data model and a Windows
I m working on windows form application. I need to show amount in words

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.