By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,926 Members | 1,806 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,926 IT Pros & Developers. It's quick & easy.

Reading a selected value out of a datagridview

P: n/a
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(DataGridViewAutoSiz eColumnsMode.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

Oct 3 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

--
Chris Ballard
"je*@auto-soft.co.za" wrote:
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(DataGridViewAutoSiz eColumnsMode.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

Oct 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.