Reading a selected value out of a datagridview

J

jed

Hello i need help on this i have read data into a gridview using sql
statement.

string loadCustomer = "SELECT * FROM Customers";
OleDbDataAdapter dataAdapter = new
OleDbDataAdapter(loadCustomer, oleDbConnectionCust);
OleDbCommandBuilder commandBuilder = new
OleDbCommandBuilder(dataAdapter);
DataTable table = new DataTable();
dataAdapter.Fill(table);
bindingSourceCust.DataSource = table;

GridViewCust.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
GridViewCust.ReadOnly = true;
GridViewCust.DataSource = bindingSourceCust;

Now when i select a row in the datagridview i need to retrieve a
string value from the first column in the selected row.Thanks
 
G

Guest

Look at the SelectedRows property on the datagridview:

GridViewCust.SelectedRows[0].Cells[0].Value

Obviously you would want to check that there is a row selected beforehand,
and that there are columns in the grid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top