灏哾ataGridView鏁版嵁杞垚DataTable
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了灏哾ataGridView鏁版嵁杞垚DataTable相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%95%b0%e6%8d%ae%e6%ba%90' title='鏁版嵁婧?>鏁版嵁婧?/a> 寰幆 datarow cells col ble sub tar val
宸茬粦瀹氳繃鏁版嵁婧愶細DataTable dt = (dataGridView1.DataSource DataTable)
鏈粦瀹氳繃鏁版嵁婧愶細
public DataTable GetDgvToTable(DataGridView dgv) { DataTable dt = new DataTable(); // 鍒楀己鍒惰浆鎹?/span> for (int count = 0; count < dgv.Columns.Count; count++) { DataColumn dc = new DataColumn(dgv.Columns[count].Name.ToString()); dt.Columns.Add(dc); } // 寰幆琛?/span> for (int count = 0; count < dgv.Rows.Count; count++) { DataRow dr = dt.NewRow(); for (int countsub = 0; countsub < dgv.Columns.Count; countsub++) { dr[countsub] = Convert.ToString(dgv.Rows[count].Cells[countsub].Value); } dt.Rows.Add(dr); } return dt; }
以上是关于灏哾ataGridView鏁版嵁杞垚DataTable的主要内容,如果未能解决你的问题,请参考以下文章