菜鸟求教控件问题

d1f2h3 2011-07-26 08:57:49
读取出来一张表
dataGridView控件 显示
ID NAME
1 AF
2 CS
3 DF


怎么取得单元格的值 使之
1af2cs3df
...全文
116 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
暖枫无敌 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 d1f2h3 的回复:]

引用 11 楼 d1f2h3 的回复:
引用 9 楼 taomanman 的回复:
C# code

string text = string.Empty;
DataTable dt = (DataTable)dataGridView1.DataSource;
foreach(DataRowView drv in dt)
{
text+=drv["ID"].ToString()+……
[/Quote]


string text = string.Empty;
DataTable dt = (DataTable)dataGridView1.DataSource;
foreach(DataRowView drv in dt.DefaultView)
{
text+=drv["ID"].ToString()+drv["NAME"].ToString();
}
this.textBox1.Text = text;


给dt加一个DefaultView属性即可
Json1204 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 d1f2h3 的回复:]

引用 4 楼 rophie 的回复:
C# code
string strs = string.Empty;
for (int i = 0; i < dataGridView1.RowCount; i++)
{

for (int j = 0; j < dataGridView1.ColumnCount; j++)
……

这个肯定超出索引了
[/Quote]

注意<号 肯定没超出


d1f2h3 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 d1f2h3 的回复:]
引用 9 楼 taomanman 的回复:
C# code

string text = string.Empty;
DataTable dt = (DataTable)dataGridView1.DataSource;
foreach(DataRowView drv in dt)
{
text+=drv["ID"].ToString()+drv["NAME"].ToString()……
[/Quote]
System.Data.DataTable”不包含“GetEnumerator”的公共定义,因此 foreach 语句不能作用于“System.Data.DataTable”类型的变量
d1f2h3 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 taomanman 的回复:]
C# code

string text = string.Empty;
DataTable dt = (DataTable)dataGridView1.DataSource;
foreach(DataRowView drv in dt)
{
text+=drv["ID"].ToString()+drv["NAME"].ToString();
}
this.textBox1……
[/Quote]
错误 1 “System.Data.DataTable”不包含“GetEnumerator”的公共定义,因此 foreach 语句不能作用于“System.Data.DataTable”类型的变量 F:\NAME\11年7月份\RFID物流系统小部分功能测试\RFID物流系统小部分功能测试\Form1.cs 45 13 RFID物流系统小部分功能测试
d1f2h3 2011-07-26
  • 打赏
  • 举报
回复
string strs = string.Empty;
for (int i = 0; i < dataGridView1.RowCount-1; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount-1; j++)
{

strs += dataGridView1.Rows[i].Cells[j].Value;
}
}

this.textBox1.Text = strs.Trim() ;
我这样写只有ID

暖枫无敌 2011-07-26
  • 打赏
  • 举报
回复

string text = string.Empty;
DataTable dt = (DataTable)dataGridView1.DataSource;
foreach(DataRowView drv in dt)
{
text+=drv["ID"].ToString()+drv["NAME"].ToString();
}
this.textBox1.Text = text;
d1f2h3 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rophie 的回复:]
C# code
string strs = string.Empty;
for (int i = 0; i < dataGridView1.RowCount; i++)
{

for (int j = 0; j < dataGridView1.ColumnCount; j++)
……
[/Quote]
这个肯定超出索引了
rophie 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rophie 的回复:]

C# code
string strs = string.Empty;
for (int i = 0; i < dataGridView1.RowCount; i++)
{

for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
……
[/Quote]
已经给你写好了啊
d1f2h3 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 taomanman 的回复:]
你要什么效果?是将所有的数据连接在一起??

1af2cs3df
[/Quote]
对 就是有几行 就是ID NAME ID NAME ID NAME ID NAME 这样继续下去
暖枫无敌 2011-07-26
  • 打赏
  • 举报
回复
你要什么效果?是将所有的数据连接在一起??

1af2cs3df
rophie 2011-07-26
  • 打赏
  • 举报
回复
string strs = string.Empty;
for (int i = 0; i < dataGridView1.RowCount; i++)
{

for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
strs += dataGridView1.Rows[i].Cells[j].Value;
}
}
textBox1.Text = strs;
d1f2h3 2011-07-26
  • 打赏
  • 举报
回复
新人 求指导
d1f2h3 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fangxinggood 的回复:]
foreach(DataGridViewRow row in datagridview1.Rows)
{
foreach(DataGridViewCell cell in row.Cells)
...
}
[/Quote]
省略的是啥呢?
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount - 1; j++)
{

text = (dataGridView1.Rows[i].Cells[j].Value).ToString() + text;
}


}
this.textBox1.Text = text;
这样可以不? 但是显示出来的 不是我要的结果
机器人 2011-07-26
  • 打赏
  • 举报
回复
foreach(DataGridViewRow row in datagridview1.Rows)
{
foreach(DataGridViewCell cell in row.Cells)
...
}

110,561

社区成员

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

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

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