将metrogrid中的行值转换为一系列列表< int>? [英] Converting a row values from metrogrid into a series of list<int>?

查看:104
本文介绍了将metrogrid中的行值转换为一系列列表< int>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这会引发异常

无法转换类型为' object  >  System.Double'键入'  System.Collections。 Generic.List`1 [System.Int32]  





我尝试过:



 List< int> gg =  new 列表< int>(); 



...

 gg =(List< int>)metroGrid1.Rows [ 1 ]。Cells [x] .Value; 

解决方案

在您的代码中

 gg =(List< int>)metroGrid1.Rows [ 1 ]。Cells [x] .Value; 



您正试图从网格第二行的第x列获取单个值。 br />


该值恰好是Double类型。



您不能将Double分配给列表(int或任何其他类型)。但是你可以值添加到列表中



尝试使用进行循环或者 foreach 循环以逐步浏览所需的每个单元格并使用 gg.Add()方法添加List的值

this throws an exception "

Unable to cast object of type 'System.Double' to type 'System.Collections.Generic.List`1[System.Int32]

"

What I have tried:

List<int> gg = new List<int>();


...

gg = (List<int>)metroGrid1.Rows[1].Cells[x].Value;

解决方案

In your code

gg = (List<int>)metroGrid1.Rows[1].Cells[x].Value;


You are trying to get a single value from column x in the second row of the grid.

That value happens to be of type Double.

You can't assign a Double to a List (of int or any other type). But you can add the value to the list

Try using a for loop or a foreach loop to step through each of the cells you want and use the gg.Add() method to add the values to the List


这篇关于将metrogrid中的行值转换为一系列列表&lt; int&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆