一、对DataGird单元格编辑输入值后,单元格还是存入的是之前值,需要对cell结束编辑,用下面方法。
int caseID = int.Parse(planCaseDataGrid.SelectedRows[0].Cells["CaseID"].Value.ToString());
if (node == null || string.IsNullOrEmpty(node.Text))
{
return;
}
int planID = Convert.ToInt32(node.Tag);
dataGridPlanTestDataView.CommitEdit((DataGridViewDataErrorContexts)1);
dataGridPlanTestDataView.BindingContext[dataGridPlanTestDataView.CurrentCell.Value].EndCurrentEdit();
//dataGridPlanTestDataView.LostFocus
二、对DataGird用MouseUp事件,可以对单元格中checkbox控件,选中状态不能记录,还是存入之前状态所以需要使用 MouseUp事件保存选中记录值
this.dataGridPlanTestDataView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PlanTestData_Click);
domain.UpdateDataByCaseIDAndPlanID(caseID, planID, dataGridPlanTestDataView.CurrentCell.Value.ToString());
三 AutoGrnerateColumns应用dataGridPlanTestDataView.AutoGenerateColumns = false;
dataGridPlanTestDataView.DataSource = planTestData;
for (int i = 0; i < planTestData.Count; i++)
{
dataGridPlanTestDataView.Rows[i].Cells["Variables"].Value = planTestData[i].Variables;
dataGridPlanTestDataView.Rows[i].Cells["Value"].Value = planTestData[i].Value;
}
四、 checkbox选中状态判断
if ((bool)dataGridPlanTestDataView.Rows[i].Cells["DefalutValue"].EditedFormattedValue == true)
五、 DataGridViewCheckBoxColumn defaultValueCheckBox = new DataGridViewCheckBoxColumn();
defaultValueCheckBox.HeaderText = "DefalutValue";
defaultValueCheckBox.Name = "DefalutValue";
defaultValueCheckBox.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
defaultValueCheckBox.FalseValue = FlatStyle.Standard;
defaultValueCheckBox.ThreeState = false;
dataGridPlanTestDataView.Columns.Insert(0,Variables);
dataGridPlanTestDataView.Columns.Insert(1,defaultValueCheckBox);
dataGridPlanTestDataView.Columns.Insert(2,value);
六、 TabControl tabControl = sender as TabControl;
if (MessageBox.Show("Are you sure to quit now?", "Information", MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
tabControl.TabPages.RemoveAt(tabControl.TabIndex + 1);
for (int i = 0; i < planCaseDataGrid.SelectedRows.Count; i++)
private void dgCase_CellClick(object sender, MouseEventArgs e)
{
Point point = dataGridCase.PointToClient(Cursor.Position);
if (dataGridCase.SelectedRows == null || dataGridCase.SelectedRows.Count == 0)
{
return;
}
DataGridViewRow selectedRow = dataGridCase.SelectedRows[0];
if (e.Button == MouseButtons.Right)
{
contextMenuStrip1.Show(dataGridCase, point);
}
}
private void BindTreeTests(IEnumerable<Plan> source)
{
foreach (Plan item in source)
{
TreeNode _node = new TreeNode();
_node.Text = item.PlanName;
_node.Tag = item.ID;
TreeViewPlan.Nodes.Add(_node);
}
}
TreeNode node = TreeViewPlan.SelectedNode;
if (node == null)
{
MessageBox.Show("please choose treeNode");
return;
}
string planName = node.Text;
int id = Convert.ToInt32(node.Tag);
dataGridCase.DataSource = dgSource;
dataGridCase.Columns["ID"].Visible = true;
dataGridCase.Columns["No"].Visible = true;
dataGridCase.Columns["No"].HeaderText = "No.";
dataGridViewTestData.Columns.Insert(0, checkBox);
int newY;
if (index == 0)
{
newY = 0;
}
else
{
newY = ucKeywordList[index - 1].Location.Y + 41;
}
for (int i = ucKeywordList.Count - 1; i >= index; i--)
{
ucKeywordList[i].Location = new Point { X = ucKeywordList[i].Location.X, Y = ucKeywordList[i].Location.Y + 32 };
checkBox.Location = new Point { X = checkBox.Location.X, Y = checkBox.Location.Y + 32 };
this.splitContainer1.Panel2.Controls.Add(keyword);
keyword.Location = new Point { X = 27 + 20, Y = newY };
CheckBox seleteCheckBox = new CheckBox();
seleteCheckBox.Size = new System.Drawing.Size { Height = 17, Width = 17 };
seleteCheckBox.Text = "";
seleteCheckBox.Tag = keyword.Name;
seleteCheckBox.Name = "checkBox" + keyword.Name;
seleteCheckBox.Location = new Point { X = 27, Y = newY + 7 };
List<FolderStructure> childRoots = orginalSource.Where(item1 => item1.ParentID == Convert.ToInt32(item.ID)).ToList();
TreeNode _node = new TreeNode();
_node.Text = item.PlanName;
_node.Tag = item.ID;
TreeViewPlan.Nodes.Add(_node);
dataGridCase.DataSource = dgSource;
TreeNode node = this.ucFolders11.TreeViewSelectedNode;