DataSet using first row as column header 将复选框列向下移动 1 行
DataSet using first row as column header move the checkbox column 1 row down
我有从 Excel 文件中填充的数据集:
OleDbConnection conn;
OleDbDataAdapter command;
conn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + filePath + " ';Extended Properties=Excel 8.0; ");
conn.Open();
firstSheetName = GetFirstSheet(conn);
command = new OleDbDataAdapter("select * from [" + firstSheetName + "]", conn);
command.TableMappings.Add("Table", "Table");
dtSet = new DataSet();
command.Fill(dtSet);
dgvInputFile.DataSource = dtSet.Tables[0];
我使用 excel 文件的第一行作为列 header。
我正在添加复选框列:
dtSet.Tables[0].Columns.Add(new DataColumn("Some header", typeof(bool)));
但是复选框列的 header 将列 1 行向下推,并且 datagridview 具有这种格式。
Some header | header 1 | header 2
--------------------------------------
checkboxcell | some value | some value
checkboxcell | some value | some value
checkboxcell | some value | some value
checkboxcell <-- Unwanted checkboxcell !!!
如何添加从第二行开始或包含 dataset.Rows.Count - 1
个元素的复选框列?
网格最后一行中的意外复选框可能是 DataGridView.AllowUserToAddRows
属性 设置为 true
(默认)的结果,这会为输入添加新行
尝试将 AllowUserToAddRows
设置为 false
以获得 dgvInputFile
顺便说一下,当 AllowUserToAddRows = true 时,网格 (dgvInputFile.RowCount
) 中的行数等于 dataset.Rows.Count + 1
我有从 Excel 文件中填充的数据集:
OleDbConnection conn;
OleDbDataAdapter command;
conn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + filePath + " ';Extended Properties=Excel 8.0; ");
conn.Open();
firstSheetName = GetFirstSheet(conn);
command = new OleDbDataAdapter("select * from [" + firstSheetName + "]", conn);
command.TableMappings.Add("Table", "Table");
dtSet = new DataSet();
command.Fill(dtSet);
dgvInputFile.DataSource = dtSet.Tables[0];
我使用 excel 文件的第一行作为列 header。 我正在添加复选框列:
dtSet.Tables[0].Columns.Add(new DataColumn("Some header", typeof(bool)));
但是复选框列的 header 将列 1 行向下推,并且 datagridview 具有这种格式。
Some header | header 1 | header 2
--------------------------------------
checkboxcell | some value | some value
checkboxcell | some value | some value
checkboxcell | some value | some value
checkboxcell <-- Unwanted checkboxcell !!!
如何添加从第二行开始或包含 dataset.Rows.Count - 1
个元素的复选框列?
网格最后一行中的意外复选框可能是 DataGridView.AllowUserToAddRows
属性 设置为 true
(默认)的结果,这会为输入添加新行
尝试将 AllowUserToAddRows
设置为 false
以获得 dgvInputFile
顺便说一下,当 AllowUserToAddRows = true 时,网格 (dgvInputFile.RowCount
) 中的行数等于 dataset.Rows.Count + 1