现在我要清空Datagridiew中的一个选中行,而不删除数据库中的数据,我在怎么做?
谢谢!
如何清空Datagridiew中的选中行
答案:2 悬赏:50 手机版
解决时间 2021-01-02 16:50
- 提问者网友:温旧梦泪无声
- 2021-01-02 09:00
最佳答案
- 五星知识达人网友:西岸风
- 2021-01-02 10:11
C#
try
{
// clear existing rows from the DataGridView.
// 将DataGridView内的现有行清空
studentClasses.Rows.Clear();
// Get the Person object for the selected student.
// 获取被选中的学生对象
Person student = (Person)studentsList.SelectedItem;
foreach (Enrollment enrollment in student.Enrollment)
{
// Create an array of row cells.
// 创建一个单元格数组作为行
object[] row = new object[4];
// Load object values from entities.
// 获取实体的各种值
row[0] = enrollment.Course.Title;
row[1] = enrollment.Course.EndDate;
row[2] = enrollment.Grade;
row[3] = enrollment.Course.Credits;
// Add the new row to the DataGridView.
// 将新行添加到DataGridView
studentClasses.Rows.Add(row);
studentClasses.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
try
{
// clear existing rows from the DataGridView.
// 将DataGridView内的现有行清空
studentClasses.Rows.Clear();
// Get the Person object for the selected student.
// 获取被选中的学生对象
Person student = (Person)studentsList.SelectedItem;
foreach (Enrollment enrollment in student.Enrollment)
{
// Create an array of row cells.
// 创建一个单元格数组作为行
object[] row = new object[4];
// Load object values from entities.
// 获取实体的各种值
row[0] = enrollment.Course.Title;
row[1] = enrollment.Course.EndDate;
row[2] = enrollment.Grade;
row[3] = enrollment.Course.Credits;
// Add the new row to the DataGridView.
// 将新行添加到DataGridView
studentClasses.Rows.Add(row);
studentClasses.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
全部回答
- 1楼网友:过活
- 2021-01-02 11:03
支持一下感觉挺不错的
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯