Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Reading data from an datatable (datagridview) cell
 

Reading data from an datatable (datagridview) cell

I have a simple database application in a C# Windows Forms application using a MS Access data base named AcQtracICG_DB.mdb with 4 tables named as follows:
Patients
PatientSessions
Results
Parameters

The database is accessed via a dataset called acQtracICG_DBDataSet and the tables are bound by the following components:
patientsBindingSource patientsTableAdapter
patientSessionsBindingSourcepatientSessionsTableAdapter
resultsBindingSource resultsTableAdapter
parametersBindingSource parametersTableAdapter

I have 4 DataGridView grids on the form with data sources named as follows:
patientsGridView patientsBindingSource
sessionsGridView patientSessionsBindingSource
resultsGridView resultsBindingSource
parametersGridView parametersBindingSource

The application builds fine and the data is displayed in the grids as expected. I can filter the data displayed in the grids by setting the BindingSource Filter property with an explicit string value (ie: "PatientID = '12345678'") and that works fine as well.

However, what I would like to do is be able to read the data from the "PatientID" column of the active row in the patientsGridView in an event handler so that I can filter the data using that value instead of an explicitly assigned value.

I have been unable to find a way to do this very simple operation and I am getting a little frustrated. I found an example using the DataGrid object instead of the DataGridView opject, but the example code will not work. It compiles, but I keep getting runtime errors about not being able to cast certain variables and I have been unble to find any help relating to the DataGridView.

Can someone please help me with this seemingly trivial operation?

jzirbes

jzirbes2  Saturday, March 10, 2007 10:30 PM
string patientID = this.dataGridView1["PatientID",this.dataGridView1.CurrentRow.Index].value.toString();
Zhi-Xin Ye  Thursday, March 15, 2007 10:18 AM
string patientID = this.dataGridView1["PatientID",this.dataGridView1.CurrentRow.Index].value.toString();
Zhi-Xin Ye  Thursday, March 15, 2007 10:18 AM

You can use google to search for other answers

Custom Search

More Threads

• update datagridview to datatable
• Paging Problem in Data Grid (Using Asp.Net with VB.Net)
• change column type of datagridview column after binding
• Importing picture from file location
• Advanced SQL Generation Options Grayed Out
• Checkbox in DatagridView Win Form
• Listview SelectedIndex()?
• DataGridViewCell Tag DataBinding
• "Provider cannot be found" error for Jet ODBC, Server 2003 R2 x64
• Two rows for headers !!