Greetings. I have a DataGridView filled with a table from the database on my form. You need to get all the Name in a separate List<> but not from the DataGridView but directly from the DataTable object. Is it possible?
Method that returns a DataTable:
public DataTable materialsNEW() { DataTable table = new DataTable(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { string get = "select * from Materials"; SqlCommand comd = new SqlCommand(get, conn); DataTable mattable = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(comd); adapter.Fill(mattable); conn.Open(); table = mattable; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } return table; } 
datagridviewfilldatagridviewand you can immediately give you an answer, so, for now, you can only guess. You can get the list, but your code is needed - Denis Bubnovvar names = table.AsEnumerable().Select(row => row.Field<string>("Name")).ToList();- Ev_Hypervar names = table.AsEnumerable().Select(row => row["Name"]).ToList();- Ev_Hyperlinq, you can read about the second question here: What is a lambda expression or on msdn - Ev_Hyper