开发者

How to create datatable from specific row datagridview

开发者 https://www.devze.com 2023-03-20 16:55 出处:网络
How Create Data Table From Top 5 or 6 row in datagridview includingco开发者_JAVA百科lumnheader also .your explanation is too short. Any how, what i understand from this is that either you have a datab

How Create Data Table From Top 5 or 6 row in datagridview including co开发者_JAVA百科lumn header also .


your explanation is too short. Any how, what i understand from this is that either you have a datable and you want to bind its just top 5 to 6 rows to data grid or u want to bring your data grid row to datatable with headers both can done through for each loop..

You can get column names like this from data

string columnName = mydatagrid.Columns[columnIndex].Name;

OR you can get both rows and column using foreach loop

 foreach(DataGridColumn col in dg.Columns)
   {
     dt.columns.Add(col.HeaderText);
   }

 foreach(DataGridRow in dg.Rows)
 {
  if(dt.Rows.Count < 6)
  //Add data to data table

 }

The same way you can apply with little modifications to get data from datatable


You can use Linq as follow

datatable.AsEnumerable().Skip(5).Take(6);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号