473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Reading a selected value out of a datagridview

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
1 1819
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: GS | last post by:
Hi, I have dataGridView with MultupleSelect property enabled and I programmatically set rows to be Selected based on checkbox being selected in DataGrid (code below). Issue is that it resets...
1
by: cc | last post by:
Hi, using the DataGridView (.NET 2005) : I have a row currently selected in the Grid (say the 3rd row showing 'Product3') Now, when I click on a column to sort the records is the 'Product3'...
3
by: Karl Rhodes | last post by:
I have a datagridview which is populated via a datatable. What I would like to dynamically set a selected row and have that row show up in the datagridview and not have to manually scroll to find...
4
by: gordon | last post by:
Hi I hav e a smallish app that has a datagridview. A user can select some columns in the datagrid, and i have a button that i would like to use to copy the rows that are selected to the...
2
by: Doug | last post by:
Hi I have a datagridview in a windows C# application and i am allowing a user to select items from the datagridview. I allow the user to copy the selected items to the clipboard and then if...
2
by: atlewis | last post by:
Hi, I'm trying to grab a string of the value in the first column of a DataGridView object on the selected row. What's the easiest way to go about that? I'm building part of a SQL statement...
1
by: bill | last post by:
Can someone tell me how you get the value of a cell in the selected row in a DataGridView control through code?
1
by: sbandalli | last post by:
Hello, I have a Datagridview which has a combobox,and 2 textbox, The combobox is bound to a Datasource(Database Sql Server and the table name is Category) ,and Datagridview is not bounded to any...
2
by: cday119 | last post by:
Hi Everyone, So I have a datagridview and it has a column called status. It has 3 values: New, Printed, and Shipped. Now a user can select multiple rows and click "set to printed". I then do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.