With this:
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
Would like to remove unnecessary rows of data
You can have code like this also,
dataGridView1.Columns.Add("Index", "Index");
dataGridView1.Columns.Add("Value", "Dice Value");
int[] theData = new int[] { 5, 2, 1, 5, 4, 1, 3, 1};
for (int i = 0; i < theData.Length; i++)
{
dataGridView1.Rows.Add(new object[] { i+1, theData[i] });
}
Output
Take a look at this .NET / C# Binding IList<string> to a DataGridView
Setting the datasource to an array will not display anything. Basically the values need to have a named property and need to implement IList to be able to be used as a DataSource. Something like this should do your bidding.
var array = new int[] { 3, 4, 4, 5, 6, 7, 8 };
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = array.Select(x => new { IntValue = x }).ToList();
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With