Reputation: 686
Let's say the datagridview has 3 columns. The Datagridview is filled with data form a SQL database. Now i want the data of the column 'age' and write it to a list so i can use the data late but i only want the INTs. Can some please help me? a code example would be lovely.
|---------|----------|----------|
| id | name | age |
|---------|----------|----------|
| 1 | john | 20 |
|---------|----------|----------|
| 2 | jane | 21 |
|---------|----------|----------|
| 3 | jack | 22 |
|---------|----------|----------|
Upvotes: 0
Views: 2046
Reputation: 1673
That is pretty simple.
For Each row As DataRow In YourDataGridView.Rows
Dim age = CInt(row("age"))
Next
Then you can do whatever you want with age variable inside that loop.
Or you can use LINQ to get list of ages.
Dim allAges = (From row As DataGridViewRow
In YourDataGridView.Rows
Select DirectCast(row.Cells("age").Value, Integer)).ToList()
Upvotes: 1