不指定数据源的情况下datagridview如何添加数据?

antinet 2009-11-27 02:21:00
DataGridView在不使用数据源的情况下,想把它仅作为一个表格使用,如何增加一行并往指定的位置写一个数据呢?
...全文
141 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
daiwoo_wang 2009-11-27
  • 打赏
  • 举报
回复
dataGridView2.Rows.Add();
dataGridView2.Rows.Add();
dataGridView2.Rows[0].Cells[0].Value = "剩余金额";
dataGridView2.Rows[1].Cells[0].Value = "购电次数";
antinet 2009-11-27
  • 打赏
  • 举报
回复
类似,但不是通过文本框,而是把DATAGRID仅作为一个表格使用,程序读到数据,然后在指定坐标的CELL现实出来,比如2行,3列,现实一个文本“123.44”,诸如此类
waddan 2009-11-27
  • 打赏
  • 举报
回复
不知道是不是通过一个文本框向dataGridView里面增加值,如果是以下可以参考
//判断是否有重复的值
if (dataGridView1.Rows.Count > 1)
{
int num = 0;
for (int j = 0; j < dataGridView1.Rows.Count - 1; j++)
{
if (this.txtBox.Text == this.dataGridView1.Rows[j].Cells[0].Value.ToString())
{
num++;
}
};
if (num == 0)
{
this.dataGridView1.Rows.Add(YourNewRow);
return;

}
}
else
{
this.dataGridView1.Rows.Add(YourNewRow);

}

}
antinet 2009-11-27
  • 打赏
  • 举报
回复
我的意思是能不能调用方法指定行、列,然后用一个SETTEXT这样的方法指定内容
cuike519 2009-11-27
  • 打赏
  • 举报
回复
http://www.devx.com/dotnet/Article/33748/1763/page/1
十八道胡同 2009-11-27
  • 打赏
  • 举报
回复
如何增加一行并往指定的位置写一个数据呢?
--
指定的位置不是数据源?
宝_爸 2009-11-27
  • 打赏
  • 举报
回复
If you are using an unbound DataGridView, you can create new rows and then add them to DataGridView.
// Sample code to add a new row to an unbound DataGridView
DataGridViewRow YourNewRow = new DataGridViewRow();
YourNewRow.CreateCells(YourDataGridView);
YourNewRow.Cells[0].Value = "Some value"
YourNewRow.Cells[1].Value = "Another value";

YourDataGridView.Rows.Add(YourNewRow);

转自
http://stackoverflow.com/questions/269354/can-you-add-data-to-a-datagrid-with-no-data-source

17,748

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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