如何使用用户生成的整数数组填充dataGridView [英] How to populate a dataGridView with an array of user generated integers
本文介绍了如何使用用户生成的整数数组填充dataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这样:
dataGridView.DataSource = theData.Select((x, index) =>
new { CreatureRoll = x, CreatureLabel = index}).OrderByDescending(x => x.CreatureRoll).ToList();
它正确生成数据,但它会生成数组中的所有行,其中不会有额外的数据有用的空数据。
It produces the data correctly, But it produces all the rows in the array with extra data that will not be useful, empty data.
img http://s21.postimg.org/t3f34aa43/list_Result.jpg?noCache=1379353500
想删除不必要的数据行
推荐答案
您可以使用LINQ从数组生成数据源。
You can use LINQ to generate the datasource from a array.
int[] theData = new int[] { 14, 17, 5, 11, 2 };
dataGridView1.DataSource = theData.Where(x => x>0).Select((x, index) =>
new { RecNo = index + 1, ColumnName = x }).OrderByDescending(x => x.ColumnName).ToList();
这篇关于如何使用用户生成的整数数组填充dataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文