Adding columns to datagrid whose datasource is datatable

  • Thread starter Thread starter Angel
  • Start date Start date
A

Angel

The Winform datagrid I'm working is already displaying data from a
datatable. How can I add columns to that datagrid? I know (or at least I
think I know) how to add the tableStyle and gridColumnStyles during design
time but I don't know what to do next (make the grid display the data). The
datatable is filled during run-time.

Thanks,
Angel
 
Never mind. I figured it out.

DataGridTableStyle ts_auditAddress = new DataGridTableStyle(); //Creates
new table Style

ts_auditAddress.MappingName = "AZMViewTable"; //Maps tablestyle to grid
datasource
DataGridTextBoxColumn DataCol_key = new DataGridTextBoxColumn(); //Adds
column to tableStyle
DataCol_key.HeaderText = "Customer Key";
DataCol_key.MappingName = "col_Key"; //maps Columnstyle DataCol_key to
column in datatable named col_Key.
ts_auditAddress.GridColumnStyles.Add(DataCol_key); //Adds Columnstyle
DataCol_key to TableStyle

dataGrid_auditAddress.TableStyles.Add(ts_auditAddress);

Thanks,
Angel
 
Add a DataGridTableStyle and then DataGridColumnStyle 's for the new
columns. Just set the MappingName to the name of the new column.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top