Denis Morgan

Denis Morgan

  • NA
  • 72
  • 22k

Use datagridview columns added from the designer on data table

Aug 14 2020 4:38 AM
  1. void loadData()    
  2. {    
  3.     dt = new DataTable();    
  4.     dt.Columns.Add("Country"typeof(string));//dont want to add these columns here want to use columns from datagrid    
  5.     dt.Columns.Add("Sales"typeof(int));//dont want to add these columns here want to use columns from datagrid    
  6.     
  7.     dt.Rows.Add(new object[] { "Argentina", 2000 });    
  8.     dt.Rows.Add(new object[] { "Belgium", 4500 });  
  9.     dataGridView1.DataSource = dt;    
  10. }  
I need to use BindingSource class to filter data and i dont know how else i can do it so that I have columns added from the designer and am able to filter datagrid. https://stackoverflow.com/questions/63245000/filter-datagrid-view-from-data-populated-from-entity-in-c-sharp is the post that I had previously posted to get help on how to filter datagridview but the solutions seems is have to bind data using datasource. I need to maintain the style and format applied to the datagridview columns on the designer
 
I have created a datagridview in designer view and added columns to it. My question is how I can access these columns from my DataTable object instead of again manually adding columns to the Datatable again(Re use columns added from datagridview on Datatable). This is what have done so far

Answers (6)