dataGridView

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

dataGridView已绑定表Score,显示ID和Score两个字段的值

我想获取dataGridView显示的Score字段的值(共10个记录)赋给10元素double类型数组array中,我用的代码是

for (i = 0; i < dataGridView1.Rows.Count ;i++ )

{

array[i] = (double )dataGridView1.Rows[i].Cells[1].Value ;

}

为啥提示强制转换无效,值必须是一个小于无限大的数呢?

应该怎样写代码?

问题补充:

MSDN上的代码也看过,网上也搜过代码,基本上都是用引用dataGridView1.Rows[行号].Cells[列号].Value ,为啥转换成double就不行了....

用array[i] = (double )dataGridView1.Rows[i].Cells[2].Value.ToString ()后又说无法将string 转换为double = =

如果去掉double强制转换又提示无法将string隐式转换为double,因为array数组是double 类型的所以应该还是要转换一下吧!

这个在MSDN上有代码示例,我就不献丑了。

你打开MSDN一看就知道了。。。

回答者:44498 - 五级2009-5-17 14:29

类型转换错误。

.ToString()后再转换!

回答者:新大软院- 六级2009-5-17 14:52 应该是转换类型有错误你把那个前面的转换类型的去掉试试

回答者:caoguangab - 四级2009-5-17 15:03 LZ试一下

array[i] = double.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString ())

不知道行不行

回答者:jdk242 - 四级2009-5-17 15:45

array[i] = dataGridView1.Rows[i].Cells[1].Value as double;

不行的话

array[i] = dataGridView1.Rows[i].Cells[1].Value.ToString() as double;

回答者:零度吹风- 四级2009-5-18 13:53

发现楼上的朋友们没提到利用Convert.来强制转换,在这里我就补充下!

array[i] = Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value);

Convert可以用于好多种类型的强制转换,你自己点下就知道了!这么好用的怎么没发现人说- -~

DataGridView(winform)的行数据提取用法

VB>NET 2008-12-15 01:18:41 阅读16 评论0 字号:大中小

搜狐博客 > C# 学习园地 > 日志 > №⑧学习→C#

2007-03-05 | DataGridView(winform)的行数据提取用法

标签:DataGridView

就是在 dataGridView1的单元格的单击事件中添加如下代码

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

{

string t1 =

dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船号"].Value.tostring();

string t2 =

dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船名"].Value.tostring();

string t3 =

dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船只类型"].Value.tostring();

string t4 =

Convert.ToDateTime(dataGridView1.Rows[dataGridView1.CurrentCellAddres s.Y].Cells["注册时间"].Value).ToShortDateString();

textBox1.Text = t1;

textBox2.Text = t2;

textBox3.Text = t3;

textBox4.Text = t4;

}

即可实现DGV的行数据的提取,也可以根据提取的一个单元格的数据进行数据库的查找,然后数据再绑定到控件上。

textbox.databindings.add("text",dataset,"login.id");//这个可以把数据绑定到控件上面了,后面那个是login表的id字段

相关文档
最新文档