新手,关于C#中DataGridView的问题

蔚蓝理想 2012-03-12 04:53:27
各位高手,看到一段代码,是C#2.0的,内容如下

int row = this.dgCourseList.CurrentCell.RowNumber; //dgCourseList是一个定义的DataGrid对象
this.dgCourseList.CurrentCell = new DataGridCell(row+1,0);

我现在在学C#4.0,在4.0下,好像没有了DataGrid,而是DataGridView,因此,找不到RowNumber属性。请问如何实现呢?我测试了一下,像下面这样提示错误:

int row = this.dgCourseList.CurrentCell.RowIndex;
this.dgCourseList.CurrentCell = new DataGridViewCell(row+1,0);//提示无法创建实例

希望高手帮忙解决,找到替换办法!
...全文
128 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
this.dgCourseList.CurrentCell = new DataGridViewCell(row+1,0);
如果没有采错的话 这句话的意思是 向下合并一个单元格
EnForGrass 2012-03-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wyzc2005 的回复:]

引用 5 楼 woaigaoweina 的回复:

你直接在row里面加参数不行吗
像这样: adapter2.Fill(ds2, "table2");
DataTable table2 = ds2.Tables["table2"];
dataGridView1.DataSource = table2;
……


能帮我解释一下我发的那段代码的含义吗?你写的我能看懂。cel……
[/Quote]
Cell就是一个单元格,你一行有几个显示字段就有几个单元格
EnForGrass 2012-03-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wyzc2005 的回复:]

引用 5 楼 woaigaoweina 的回复:

你直接在row里面加参数不行吗
像这样: adapter2.Fill(ds2, "table2");
DataTable table2 = ds2.Tables["table2"];
dataGridView1.DataSource = table2;
……


能帮我解释一下我发的那段代码的含义吗?你写的我能看懂。cel……
[/Quote]
看MSDN你和快就学会使用这个数据控件,http://msdn.microsoft.com/zh-cn/library/e0ywh3cz(v=vs.80).aspx
蔚蓝理想 2012-03-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 woaigaoweina 的回复:]

你直接在row里面加参数不行吗
像这样: adapter2.Fill(ds2, "table2");
DataTable table2 = ds2.Tables["table2"];
dataGridView1.DataSource = table2;
……
[/Quote]

能帮我解释一下我发的那段代码的含义吗?你写的我能看懂。cell范围是什么呢?比如row是一行,而col是一列。
woaigaoweina 2012-03-12
  • 打赏
  • 举报
回复
你直接在row里面加参数不行吗
像这样: adapter2.Fill(ds2, "table2");
DataTable table2 = ds2.Tables["table2"];
dataGridView1.DataSource = table2;
dataGridView1.Columns[1].HeaderText = "书名";
dataGridView1.Columns[2].HeaderText = "作者";
像这样 属性一样
蔚蓝理想 2012-03-12
  • 打赏
  • 举报
回复
3楼,是向下面这样找吗?可是还有不会弄的。
我专业外的,学这个,刚入门,能给我写下代码啊?
int myRow = this.dgvCourseList.CurrentRow.Index;
this.dgvCourseList.CurrentCell = new DataGridViewCell(这里参数怎么弄呢?);

卡索瓦 2012-03-12
  • 打赏
  • 举报
回复
例如DataGridView的一个对象dgvList,可以用dgvList.CurrentRow.Index + 1;行号不就出来了吗;你用的DataGrid是WebForm控件,在WinForm里是不行的;另外你如果想在DataGridView中加行号,可以在绑定数据的时候加一列或者重绘控件。
蔚蓝理想 2012-03-12
  • 打赏
  • 举报
回复
那能帮助我解释一下2.0代码的含义吗?那个RowNumber什么意思呢?
bdmh 2012-03-12
  • 打赏
  • 举报
回复
不知道new DataGridViewCell(row+1,0);用意何在

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧