您好我是c#wpf编程的新手我只需要创建一个我做的一些细节的数据网格,一个主要任务是添加序列号将增加为1,2,3,4等.as当我从数据网格中删除一个记录时,根据它重新排列序列号,例如:sno:1,2,3,4,5,6。 删除第3行后,应该是1,2,3,5,5 1,2,3,5,6。 类似于在1,2,3之间插入一行后添加它应该是1,2,3,4任务是行必须在2和3之间添加新行帮助需要
void mbtninsertstep_Click(object sender, RoutedEventArgs e) {
int rowindex = mdatagridedit.Items.IndexOf(mdatagridedit.CurrentCell);
if (rowindex >= 0) {
int rowcount = programtable.Rows.Count;
msteps.Add(new Steps { mStepno = count, mPosition = "0",
mRepeat = "NONE", mCount = "1", mAftercut = "NONE" });
int p = rowindex + 1;
for (int i = 0; i < rowcount + 1; i++) {
programtable.Rows[i][0] = p++;
} edited = true;
}
}
删除按钮代码
插入按钮代码。
void mbtndeletestep_Click(object sender, RoutedEventArgs e)
{
int deleterow;
DataGridView dg = new DataGridView();
// msteps.Remove((Steps)mdatagridedit.SelectedItem);
int rowindex = dg.CurrentRow.Index;
if (rowindex >= 0) {
int rowcount = programtable.Rows.Count;
int temp = dg.CurrentCell.RowIndex;
programtable.Rows.RemoveAt(temp);
int p = temp + 1;
for (int i = rowindex; i < rowcount - 1; i++) {
programtable.Rows[i][0] = p++;
}
int RowCountAfterDeleting = programtable.Rows.Count;
}
//int p = mdatagridedit.Items.Count;
// if (mdatagridedit.SelectedItem == null) {
// System.Windows.Forms.MessageBox.Show("Select an row");
// } else {
//msteps.RemoveAt(mdatagridedit.SelectedIndex);
//int p = mdatagridedit.SelectedIndex + 1;
// for(int i = mdatagridedit.SelectedIndex;
i < mdatagridedit.Items.Count - 1; i++){
// Steps step = new Steps();
// step.mStepno = p - 1;
// } int p1 = programtable.Rows.Count;
//}
}