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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:02:35+00:00 2026-05-12T06:02:35+00:00

I have a windows forms application containing a datagridview control. The datagridview is populated

  • 0

I have a windows forms application containing a datagridview control. The datagridview is populated by the contents of an xml file. At the moment, all of the columns are displayed as datagridviewtextboxcolumns. I want to select one that is populated by a particular xml tag and display it’s content in a datagridviewcomboboxcolumn along with 2 other options.

EXAMPLE:

<SMS>
<Number>+447931663542</Number> 
<DateTime>2009-07-12T17:00:02</DateTime> 
<Message>YES</Message> 
<FollowedUpBy>Unassigned</FollowedUpBy> 
<Outcome>Resolved</Outcome>
</SMS>

The OUTCOME tag is the column that I would like to be displayed as a comboboxcolumn in the datagridview. If for example the tag is empty and contains no data, then I want to display nothing, but have the comboboxcolumn populated with 3 possible options to choose from (Unresolved, Resolved, Pending). If however the tag contains data, I want that particular item to be displayed in the comboboxcolumn, and have the other two options available to be selected.

Help in achieving this would be appreciated greatly!

Regards,

EDIT:
Currently I use this code:

     colOutcome = new DataGridViewComboBoxColumn();
        colOutcome.HeaderText = "Outcome";
        colOutcome.Width = 90;
        colOutcome.Items.AddRange("Resolved", "Unresolved", "Pending");
        this.dataGridView1.Columns.Insert(1, colOutcome);
        this.dataGridView1.Columns[1].Name = "OutcomeColumn";

This code above populates the combobox. THE PROBLEM IS: When The xml document populates the datagridview, the outcome column just appears as a textbox column, containing the data inbetween the outcome tags in the xml file. My point is, how can i get the datagridview to realise when it reads the outcome column that it needs to be changed into a combobox column and then display the data that way, along with the other potentially selectable options in the combobox?! Currently the datagridview gets populated with all columns as textboxcolumns containing the data, as well as a seperate combobox column which is not what I want. I need the application to merge the outcome column and its data with the code above.

Any ideas?

  • 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-12T06:02:35+00:00Added an answer on May 12, 2026 at 6:02 am

    Updated Answer

    You could pass in the XML document to a function that will loop through each node and determine whether it should be a ComboBox one or not i.e. if the name is “Outcome”.

    private void CreateColumns(XmlDocument doc)
    {
        foreach (...) // loop through each node in xml document
        {
             if (node.Name == "Outcome")
             {
                  var items = new List<string>() { "Resolved", "Unresolved", "Pending" };
                  this.dataGridView1.Columns.Add(CreateComboBoxColumn(node.Name, items));
             }
             else
             {
                  this.dataGridView1.Columns.Add(String.Format("col{0}", node.Name), node.Name);
             }
        }
    }
    

    Then your code for creating the Outcome column would be:

    private DataGridViewComboBoxColumn CreateComboBoxColumn(string colHeaderText, List<string> items)
    {
        var colOutcome = new DataGridViewComboBoxColumn(); 
        colOutcome.HeaderText = colHeaderText; 
        colOutcome.Width = 90; 
        colOutcome.Items.AddRange(items.ToArray());
        colOutcome.Name = String.Format("col{0}", colHeaderText);
        return colOutcome;   
    }
    

    You would then just call CreateColumns on the form load event and pass in your XML. You should only need to create the columns once.

    My advice would be to have a similar function that will find all the SMS elements and add a new row populating it with the information in each node.

    public void MyForm_Load(object sender, EventArgs e)
    {
         var doc = new XmlDocument(filename);
         CreateColumns(doc);
         CreateRows(doc);
    }
    

    Hope that helps.

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

Sidebar

Ask A Question

Stats

  • Questions 155k
  • Answers 155k
  • 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 We do exactly this (and more:) Create a wxi file… May 12, 2026 at 10:42 am
  • Editorial Team
    Editorial Team added an answer Just join them one by one: for (Thread thread :… May 12, 2026 at 10:42 am
  • Editorial Team
    Editorial Team added an answer The first question you need to ask is this: is… May 12, 2026 at 10:42 am

Related Questions

We have an application containing a lot of user controls that update frequently based
Visual Studio (2005 Professional), Windows Forms application : I've got a form which contains
I have a .NET class library containing a class with a method that performs
My Goal I would like to have a main processing thread (non GUI), and
I am experiencing a weirdest thing for the last couple of days. I found

Trending Tags

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

Top Members

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.