private void AddButton_Click(object sender, EventArgs e) { if (SettingDataGridView.SelectedCells.Count > 1) //添加到选中一行的前面 { int position = SettingDataGridView.SelectedCells[0].RowIndex; DataGridViewRow dataGridViewRow = new DataGridViewRow(); DataGridViewTextBoxCell indexCell = new DataGridViewTextBoxCell(); indexCell.Value = position + 1; dataGridViewRow.Cells.Add(indexCell); for (int i = 0; i < SettingDataGridView.Rows.Count; i++) { if (i >= position) { SettingDataGridView[ColumnIndex.Index, i].Value = i + 2; } } SettingDataGridView.Rows.Insert(SettingDataGridView.SelectedCells[0].RowIndex, dataGridViewRow); SettingDataGridView.ClearSelection(); SelectRow(position); } //最后一行添加 else { int position = SettingDataGridView.Rows.Count; DataGridViewRow dataGridViewRow = new DataGridViewRow(); DataGridViewTextBoxCell indexCell = new DataGridViewTextBoxCell(); indexCell.Value = position + 1; dataGridViewRow.Cells.Add(indexCell); SettingDataGridView.Rows.Add(dataGridViewRow); SelectRow(position); } }
private void DownButton_Click(object sender, EventArgs e) { if (SettingDataGridView.SelectedCells.Count > 1) { int position = SettingDataGridView.SelectedCells[0].RowIndex; ExChangeRowValue(position, position + 1); SettingDataGridView.ClearSelection(); SelectRow(position + 1); } }
private void RemoveButton_Click(object sender, EventArgs e) { if (SettingDataGridView.SelectedCells.Count > 1) { int position = SettingDataGridView.SelectedCells[0].RowIndex; for (int i = 0; i < SettingDataGridView.Rows.Count; i++) { if (i >= position) { SettingDataGridView[ColumnIndex.Index, i].Value = i; } } SettingDataGridView.Rows.RemoveAt(position); SettingDataGridView.ClearSelection(); SelectRow(position); } }
private void InitDataGrid(string path) { DataBaseManager.GetInstance().Init(path); List <Item> tmpItems = DataBaseManager.GetInstance().GetDatas <Item>(ItemManager.DATABASE_TABLE_ITEM_NAME); DataBaseManager.GetInstance().Deinit(); if (tmpItems.Count > 0) { foreach (Item item in tmpItems) { DataGridViewRow viewRow = new DataGridViewRow(); //序号 DataGridViewTextBoxCell indexCell = new DataGridViewTextBoxCell(); indexCell.Value = item.Index; viewRow.Cells.Add(indexCell); //名称 DataGridViewTextBoxCell nameCell = new DataGridViewTextBoxCell(); nameCell.Value = item.ItemName; viewRow.Cells.Add(nameCell); //可执行文件路径 DataGridViewTextBoxCell executeCell = new DataGridViewTextBoxCell(); executeCell.Value = item.ExecutablePath; viewRow.Cells.Add(executeCell); //参数 DataGridViewTextBoxCell paramsCell = new DataGridViewTextBoxCell(); paramsCell.Value = item.Parameters; viewRow.Cells.Add(paramsCell); //超时 DataGridViewTextBoxCell timeoutCell = new DataGridViewTextBoxCell(); timeoutCell.Value = item.TimeOut; viewRow.Cells.Add(timeoutCell); //重试 DataGridViewTextBoxCell repeatCell = new DataGridViewTextBoxCell(); repeatCell.Value = item.RepeatCount; viewRow.Cells.Add(repeatCell); //是否测试 DataGridViewCheckBoxCell needtestCell = new DataGridViewCheckBoxCell(); needtestCell.Value = item.NeedTest; viewRow.Cells.Add(needtestCell); SettingDataGridView.Rows.Add(viewRow); } SettingDataGridView.ClearSelection(); } }
private void SelectRow(int row) { if (SettingDataGridView.RowCount > 0) { if (row > SettingDataGridView.RowCount - 1) { row = SettingDataGridView.RowCount - 1; } SettingDataGridView[ColumnIndex.Index, row].Selected = true; SettingDataGridView[ColumnName.Index, row].Selected = true; SettingDataGridView[ColumnExecute.Index, row].Selected = true; SettingDataGridView[ColumnParamerters.Index, row].Selected = true; SettingDataGridView[ColumnTimeOut.Index, row].Selected = true; SettingDataGridView[ColumnRepeatCount.Index, row].Selected = true; SettingDataGridView[ColumnNeedTest.Index, row].Selected = true; } else { SettingDataGridView.ClearSelection(); } }