我有从Excel文件中填充的DataSet:
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文件的第一行作为列标题。 我添加了复选框列:
dtSet.Tables[0].Columns.Add(new DataColumn("Some header", typeof(bool)));
但是复选框列的标题将第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
元素的复选框列?
答案 0 :(得分:0)
意外复选框可以是button1 = QtGui.QPushButton("This is button1", self)
button1.setToolTip("You have moused over Button1)
属性设置为DataGridView.AllowUserToAddRows
(默认)的结果,这会为输入添加新行
尝试为true
AllowUserToAddRows
到false
顺便说一句,当AllowUserToAddRows = true时,网格中的行数(dgvInputFile
)等于dgvInputFile.RowCount