473,769 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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";
OleDbDataAdapte r dataAdapter = new
OleDbDataAdapte r(loadCustomer, oleDbConnection Cust);
OleDbCommandBui lder commandBuilder = new
OleDbCommandBui lder(dataAdapte r);
DataTable table = new DataTable();
dataAdapter.Fil l(table);
bindingSourceCu st.DataSource = table;

GridViewCust.Au toResizeColumns (DataGridViewAu toSizeColumnsMo de.AllCellsExce ptHeader);
GridViewCust.Re adOnly = true;
GridViewCust.Da taSource = bindingSourceCu st;

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 1832
Look at the SelectedRows property on the datagridview:

GridViewCust.Se lectedRows[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";
OleDbDataAdapte r dataAdapter = new
OleDbDataAdapte r(loadCustomer, oleDbConnection Cust);
OleDbCommandBui lder commandBuilder = new
OleDbCommandBui lder(dataAdapte r);
DataTable table = new DataTable();
dataAdapter.Fil l(table);
bindingSourceCu st.DataSource = table;

GridViewCust.Au toResizeColumns (DataGridViewAu toSizeColumnsMo de.AllCellsExce ptHeader);
GridViewCust.Re adOnly = true;
GridViewCust.Da taSource = bindingSourceCu st;

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
1600
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 Selected rows each time I select a new row. What am I doing wrong? private void dgrResults_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (((DataGridView)sender).CurrentCell is DataGridViewCheckBoxCell)
1
4272
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' row located as first row in the Grid but not selected (highlighted) anymore. The position of the selected (highlighted)-row doesn't change and is still located on the 3rd row, thus showing a dfifferent product. I don't want
3
23541
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 the selected row. I had a look for all kind of "datagridview1.rows(i).focus" but there doesnt seem to be anything. Can anyone help? I know this must be quite simple to do but cant find it.
4
5852
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 clipboard or to a text file. Any ideas how to accomplish this? I have all the controls working in this form apart from this feature.
2
4426
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 they chose, to past to the notepad application. But the items that are selected seem to be pasted in the reverse order than the user selected them - for example if the user selected items 1 3 5 then
2
21237
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 inside a loop: strSQL &= Str(myGrid.SelectedRow(ColumnIndex)) & "," & Str(dgvResults.Item(1, i)) & "," & Str(Now) & ")"
1
1277
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
5237
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 datasource. When the user selects an item in the combobox,and enters the item(text) in the 2 text box , I want all the 3(combobox selected item, and the entered text in the 2 textbox) of them to store it a a table name called...
2
11599
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 a foreach loop on datagridview.selectedrows and change the status to printed. Now the problem is that if the datagridview is sorted by status, when the status is changed from new to printed, that row is moved from being under new to printed and all...
0
10223
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.