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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:58:06+00:00 2026-06-13T07:58:06+00:00

I have a datagrid I must fill with a mix of Columns dynamically created

  • 0

I have a datagrid I must fill with a mix of

  • Columns dynamically created with code
  • Columns dinamically created retrieving data from a query (dynamic, naturally)

DataTable table;

using (SqlDataReader dr = cmd.ExecuteReader())
{
    table.Load(dr);

    // Insert row number column
    DataGridViewTextBoxColumn rowColumn = new DataGridViewTextBoxColumn()
    {
        HeaderText = "Row",
        Width = 40,
        ReadOnly = true,
        Frozen = true
    };
    dgv.Columns.Insert(0, rowColumn);

    // Insert grouping column
    DataGridViewComboBoxColumn groupColumn = new DataGridViewComboBoxColumn()
    {
        HeaderText = "Grouping",
        Width = 70,
        DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox,
        FlatStyle = System.Windows.Forms.FlatStyle.Flat,
        Frozen = true
    };
    groupColumn.Items.AddRange(new object[] { "-", "Group 1", "Group 2"});
    dgv.Columns.Insert(1, groupColumn);

    // Populate row & grouping columns
    .................

    dgv.DataSource = table;
}   

DataGridView is filled with desired data and user can alter everything he wants.
Finally I need to sort rows according to the modified content of columns edited values (both the created ones and the databound ones): how can I do this?

Databound datagridviews cannot be sorted using Sort() nor can I use Sort method of DataTable (or DataView I could put in the middle) because I have extra data.
I’m stuck with this…

  • 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-13T07:58:07+00:00Added an answer on June 13, 2026 at 7:58 am

    Add the columns in your table instead of your datagridview.
    This will make the column databound instead of creating it “manually”.
    Then to turn the column into a combobox column have a look at this SO link:
    How to change a datagridview cell style from the default textbox to combobox in vb.net?

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

Sidebar

Related Questions

I have a wpf datagrid that has it's columns generated dynamically in code and
I have a WPF DataGrid that must have the row headers and columns added
I have a query that returns 2 columns from joining 2 entities as the
I have datagrid whichs items source is domainDataSource. How i can refresh Domain data
I have a datagrid in C#.net I have made some columns in grid editable.
I have quastion about DataGrid in WPF .NET 4. Here is XAML code with
I have a WPF DataGrid templatecolumn that has a DataTemplate for an AutoCompleteBox from
I am Binding a Datagrid to dynamic data via IDictionary: http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-via-idictionary/comment-page-1/#comment-8681 But I do
I have a datagrid: <mx:DataGrid id=resultsDataGrid height=328 width=604 paddingRight=0 editable=false y=43 horizontalCenter=0> <mx:columns> <mx:DataGridColumn
I'm having trouble pasting from a csv into the wpf datagrid - I have

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.