dataGridView中如何判断单元格中的值为数字还是字符类型?
List<double> values = new List<double>(); for (int i = 0; i < dataGridView.Columns.Count; i++)
{
for (int j = 0; j < dataGridView.Rows.Count; j++)
{
if (dataGridView.Rows[j].Cells[i].Value != DBNull.Value)
values.Add(Convert.ToDouble(dataGridView.Rows[j].Cells[i].Value));
}
} 这段代码只能对输入数值类型的值进行操作,如果dataGridView输入字符类型的,就报错! 所以想问下如何判断单元格中的值为字符类型? 高手指点下!
解决方案 »
- WCF传输实体!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 数据库装入多级树形菜单
- 求助:关于查询的问题: 用SELECT查询时出了问题怎么搞??
- 晕啊,SendKeys.Send("{F8}")竟然不起作用,救命啊。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
- FormsAuthentication.SetAuthCookie 方法 (String, Boolean)的用法或含义?什么叫身份验证票据,有什么作用?什么叫创建身份验证票并将其
- 各位高手帮帮小弟的忙吧。小弟现在想找一个控制扫描仪的.NET控件(付费也行)。
- 添加新数据源,出错
- C#如何模拟flash播放器请求的视频
- 求助:在自己的应用程序中如何获得当前浏览器中的URL(假设浏览器开着)?
- 如何在C# web 应用程序中,弹出对话框,并获得用户的选择
- 请专家知道我一下吧falsh整合到*.dll中的方法.
- 关于泛型的问题
Convert.ToDouble(dataGridView.Rows[j].Cells[i].Value)
catch ex
response.write("not Numeric")
end try
if(typeof(string) == dataGridView.Rows[j].Cells[i].Value.GetType())
{
//code here
}
{
for (int j = 0; j < dataGridView.Rows.Count; j++)
{
if (dataGridView.Rows[j].Cells[i].Value != DBNull.Value)
{
try{
values.Add(Convert.ToDouble(dataGridView.Rows[j].Cells[i].Value));
}
catch
{
messagebox.show("转换错误!");
}
}
}
}
{
if (dataGridView.Columns[i].ValueType == typeof(string)) continue;
if (dataGridView.Rows[j].Cells[i].Value != DBNull.Value)
values.Add(Convert.ToDouble(dataGridView.Rows[j].Cells[i].Value));
}