0

Is it Possible to merge two Columns to a single column for only one row in a datatable using C#? similar to Merge cells option of the excel

DataTable table = new DataTable();
table.Columns.Add("Column1",typeof (String))
table.Columns.Add("Column2",typeof (String))
table.Columns.Add("Column3",typeof (String))
table.rows.add(table.newrow());

i want to merge column2 and column3 for only first row of the Datatable.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user1010186
  • 171
  • 1
  • 4
  • 14
  • 1
    Why would you do that? – dario Jan 05 '15 at 15:19
  • `DataTable` is a data structure not a UI feature. Your visual control is the one that need to display the result of the 1,2,3... columns into a single cell. Look for binding values. It's easier to bind in WPF but still perfectly doable in Winforms. Search on the web for the following keywords with your visual control : `Binding, Data binding` you will find what you need. Otherwise if the control cant you will need to create a new column and iterate to fill that column with the value of the others concatenated and then bind the data to the control. Inefficient and harder to manager later on – Franck Jan 05 '15 at 15:38

1 Answers1

1

DataTable is not a visible aspect, there will be no need of merging 2 columns, please give the specific requirement. I don't think it is possible too.

Or better create different datatables and merge the datatables rather than merging the columns in a row.

Then in case of gridview scenario, you could have look here :-

GridView with merged cells

Community
  • 1
  • 1
King
  • 183
  • 10