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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:52:47+00:00 2026-05-19T17:52:47+00:00

I’m quite new to C# (coming from a Java background) and I’m working on

  • 0

I’m quite new to C# (coming from a Java background) and I’m working on a Form to quickly manage different data (e.g. Users, Domains, Computers) along with providing utilities that use the data.

To avoid confusion the following is a summary of the example data structure;

<User>
    <Name>joe</Name>
    <Domain>europa</Domain>
</User>
<Domain>
    <Name>europa<Name>
<Domain>
<Domain>
    <Name>group</Name>
</Domain>
<Computer>
    <Name>localhost</Name>
</Computer>

In my Form I have tab pages for each data, each containing a DataGridView (containing a column for each member) to allow for simple management. I’m using a single DataSet which reads the data from an XML file (using a schema) when the Form Load event is fired. After reading the data I am setting the tables as the DataSource of their respective DataGridView using the code;

userDataGridView.DataSource = dataSet.Tables["User"];
domainDataGridView.DataSource = dataSet.Tables["Domain"];
computerDataGridView.DataSource = dataSet.Tables["Computer"];

This is working properly for the Domain and Computer DataGridViews as they only have single text columns which are mapped to the Name properties. However, the Domain column of for the User DataGridView is a combo box and I need that to contain all the possible Domains (e.g. europa, group) as well as the selected Domain being bound to User.Domain (also, the User.Domain being initially selected).

My main question is how I achieve the above but I also have some additional questions hopefully someone can answer;

  1. I’m assuming that changes made to a DataGridView are immediately persisted in the underlying XML file as I am reading it from the build’s output directory. Is this correct or is additional configuration/process required?
  2. During my attempts at getting this to work I tried to use a DataRelation as follows;
    DataRelation dataRelation = new DataRelation("Domain users", 
        dataSet.Tables["Domain"].Columns["Domain"], 
        dataSet.Tables["User"].Columns["Domain"]);
    dataSet.Relations.Add(dataRelation);
    

    How exactly do DataRelations work and what effect do/can they have?

In case it helps you understand/explain I am using the SharpDevelop IDE for working on this application.

Thanks in advance.

  • 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-19T17:52:48+00:00Added an answer on May 19, 2026 at 5:52 pm

    As you have already found out, the DataGridView is very powerful and does most of the work in an automagically way. Unfortunately you run into problems if these defaults doesn’t match your preferences (like using a ComboBox for a text property).

    To get the DataGridViewComboBoxColumn into the proper place you can do this programmatically within your code or (if possible) do it with the designer (in Visual Studio don’t know if SharpDevelop supports it).

    Using the (Visual Studio) Designer

    For this scenario it is necessary that the structure of the data is known at design time by providing a class holding all (or more) informations as simple properties (like a person class with properties name, age, etc.). If this is available you can add a BindingSource to your control and click in the properties window at the button next to the DataSource property. Select Add Project Data Source and select Object and select your desired object.

    Now you have a binding source configured with a specific type of DataSource. Next select your DataGridView and change the DataSource property to the recently created binding source.

    After this the DataGridView will automatically be populated with a column for each property. Now you can easily step into the Columns property and change the behaviour and type of each column as you like.

    To connect your concrete data with the DataGridView just apply your table to the binding source.

    Doing the same at runtime

    If you have Visual Studio and followed the above steps you can afterwards easily take a look into the Designer.cs file to find how Visual Studio did all the stuff. There is nothing you can’t do also manually. So if you need to just do it.

    Simply create a DataGridViewComboBoxColumn, set the DataPropertyName and HeaderText and you’ve got a good starting point. Get the IndexOf() the column you want to replace, remove it and Insert() your freshly created column at the position you want.

    Before the Grid can show some data (in the ComboBoxColumn) you need to provide a list with the possible values. For this purpose the comboBoxColumn has a DataSource property on itself where you can provide the desired values. With the simplest scenario you just provide an ICollection<string>, but you can also give something more complex like List<KeyValuePair<Enum, string>>. If that’s the case you should also set the properties ValueMember and DisplayMember to tell the ComboBox which properties of the objects should be used to populate the list.

    Maybe with these informations given you should take a look at the MSDN article about the DataGridViewComboBoxColumn and study the example. This should give you some additional hints on how to set it up properly.

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

Sidebar

Related Questions

No related questions found

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.