想不出来了,提问。。。

xiaotiange 2010-06-25 02:34:06
WINFORM程序

一个datagridview
3列 ( DataGridViewCheckBoxColumn,DataGridViewTextBoxColumn,DataGridViewButtonColumn)

我在textbox列中填写一些数字, 当然可以每行都有填写,也可以隔开一行或几行填写
现在我要把有数值的单元格里的值拿出来放到数组里,空值的抛弃掉不管它
请问怎么处理??
试了好几种办法也没搞定……
...全文
87 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
宇峰科技 2010-06-25
  • 打赏
  • 举报
回复
bool isSel = false;
int rowcount = 0;

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (Convert.ToString(dataGridView1.Rows[i].Cells[1].Value) != null && Convert.ToString(dataGridView1.Rows[i].Cells[0].Value) != null)
{
isSel = Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value);
if (isSel)
{
rowcount++;
strarr = new string[rowcount];
}
for (int j = 0; j < rowcount; j++)
{
if (Convert.ToString(dataGridView1.Rows[j].Cells[1].Value) == null)
{
continue; strarr[j] = dataGridView1.Rows[j].Cells
[1].Value.ToString();

}
}

}

}

风之影子 2010-06-25
  • 打赏
  • 举报
回复
if (string.isNullOrEmpty(Convert.toString(dataGridView1.CurrentRow.Cells[0].Value))) 
{
MessageBox.Show("还好");
}
风之影子 2010-06-25
  • 打赏
  • 举报
回复
string.isNullOrEmpty代替你的=="";
xiaotiange 2010-06-25
  • 打赏
  • 举报
回复
把有值的取出来 空的不要
Wude_S 2010-06-25
  • 打赏
  • 举报
回复
不明白什么意思,就是简单的取值吗?空的不要
hhc123 2010-06-25
  • 打赏
  • 举报
回复
DataGridViewRow dr;
dr.IsNewRow一行是否为空
dr.cells[] 看有没有空值

xiaotiange 2010-06-25
  • 打赏
  • 举报
回复
也可以推翻上面的重新给个指导
xiaotiange 2010-06-25
  • 打赏
  • 举报
回复

bool isSel = false;
int rowcount = 0;

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (Convert.ToString(dataGridView1.Rows[i].Cells[1].Value) != null && Convert.ToString(dataGridView1.Rows[i].Cells[0].Value) != null)
{
isSel = Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value);
if (isSel)
{
rowcount++;
strarr = new string[rowcount];
}
for (int j = 0; j < rowcount; j++)
{
if (Convert.ToString(dataGridView1.Rows[j].Cells[1].Value) == null)
{
//在此处理
strarr[j] = dataGridView1.Rows[j].Cells[1].Value.ToString();

}
}

}

}

风之影子 2010-06-25
  • 打赏
  • 举报
回复
你处理到那了,把你的代码贴出来帮你改。

注意对空值的处理

110,570

社区成员

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

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

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