Getting values from datagrid view column to list<>
My main form in my application has a datagrid view that can have 1 to many user selected inputs. Column 8 of this grid is for the user to input "time in minutes." I have a separate class where I have built a timer that counts down from whatever开发者_运维百科 time the user specifies down to 0. What I need is to create a series of alarms that go off as the timer counts down that are triggered by the user input values in column 8 of my datagrid.
I think the best way to do this is to build a list<> from the values in the datagrid. I for whatever reason can't quite figure out how to get the values from the datagrid in to a list<> in my other class.
Hopefully I explained in a way that makes sense.
Just did this off the top of my head
List<int> listOfMinutes = new List<int>();
for (int i = 0;i < dataGridView1.Rows.Count; i++)
{
// either ".Text" or ".Value"...can't remember
listOfMinutes.Add(int.Parse(dataGridView1.Rows[i].Cells[7].Text));
}
That should give you a list of the data in Column 8. This is assuming you mean Column 8 when looking at the Grid.
精彩评论