select row in Datagridview C#
-
Hi all Im using C# 2005, I have a button search which when you click refreshes the datagridview and displays the search results that's fine. Now what I want is when I select a row or cell the data in that row appear on the respective textboxes in the form to allow the user to update if they want, is there a way that I can do this or another way maybe. Any help will be appreciated!!
private void btnSearch_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text ; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); dataGridView.AutoGenerateColumns = true; dataGridView.DataSource = ds; dataGridView.DataMember = "ecmain"; datatryConn.Close();
Thanx in advance Csanda -
Hi all Im using C# 2005, I have a button search which when you click refreshes the datagridview and displays the search results that's fine. Now what I want is when I select a row or cell the data in that row appear on the respective textboxes in the form to allow the user to update if they want, is there a way that I can do this or another way maybe. Any help will be appreciated!!
private void btnSearch_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text ; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); dataGridView.AutoGenerateColumns = true; dataGridView.DataSource = ds; dataGridView.DataMember = "ecmain"; datatryConn.Close();
Thanx in advance Csandawell I'm out of touch from desktop applicatoins for quite sometime now but if u want to show the data of a cell of a dgv in a textbox then u need to use an event , its called onCellClick I think. use its DatagridvieweventArgs object that will give the RowIndex and ColumnIndex Properties to get the data of that particular cell. I'm sorry I cant give u the code coz I'm bussy in another project at the moment Hope it helps
Rocky You can't climb up a ladder with your hands in your pockets.
-
well I'm out of touch from desktop applicatoins for quite sometime now but if u want to show the data of a cell of a dgv in a textbox then u need to use an event , its called onCellClick I think. use its DatagridvieweventArgs object that will give the RowIndex and ColumnIndex Properties to get the data of that particular cell. I'm sorry I cant give u the code coz I'm bussy in another project at the moment Hope it helps
Rocky You can't climb up a ladder with your hands in your pockets.
-
You can use
gridview.CurrentCell.RowIndex
or from the event args of the CellClick evente.RowIndex
. Hope it helps.I will use Google before asking dumb questions
-
what do u mean it doesnt recognize rowindex and columnindex. show me the code plz
Rocky You can't climb up a ladder with your hands in your pockets.