Retrieving single values from a DataGrid at RowIndex xy

Joined
Feb 7, 2010
Messages
2
Reaction score
0
Hello

I hope someone can help a C# newstarter.

I have a DataGrid where I fill in my data via a DataSet.

Now I created a method which should open a new form once I doubleclick the cell content of my DataGrid.

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
i = e.RowIndex;
j = e.ColumnIndex;

string rowtest = "";

string conString = "Data Source=localhost\\TESTDB;Initial Catalog=nordwind;Integrated Security=SSPI";
conn = new SqlConnection(conString);

conn.Open();

ds1 = new DataSet();
adapter = new SqlDataAdapter("Select * from Artikel", conn);
adapter.Fill(ds1, "Artikel");
...
}


What I want is to display the value of each column from my DataGrid at position "i" in a "TextBox".

Lets say my DataGrid has two columns. Column "A" has the value "blah1" and column "B" the value "blah2" @ RowIndex i.

"blah1" should be displayed in TextBox1, and "blah2" in TextBox2, once I doubleclick the row.. (or rather Cell, since I don't know any event, which would mark the whole row).

I guess this shouldn't be so hard, having the RowIndex.. but it seems I am to stupid to figure this out.

I have been struggling with this simple issue for two days now.. read several tutorials, but none seemed to cover my problem.

Any small hint would be welcome.
 
Last edited:
Joined
Feb 7, 2010
Messages
2
Reaction score
0
Solved

I am not sure if someone used telepathy, but the issue was resolved. :)

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
i = e.RowIndex;
j = e.ColumnIndex;

string rowtest1, rowtest2 = "";

string conString = "Data Source=localhost\\TESTDB;Initial
Catalog=nordwind;Integrated Security=SSPI";
conn = new SqlConnection(conString);

adapter = new SqlDataAdapter();
command = new SqlCommand("Select * from Artikel", conn);
adapter.SelectCommand = command;

conn.Open();

ds1 = new DataSet();

adapter.Fill(ds1);

rowtest1 = ds1.Tables[0].Rows["ArtikelName"].ToString();
rowtest2 = ds1.Tables[0].Rows["Liefereinheit"].ToString();

textlabel1.Text = rowtest1;
textlabel2.Text = rowtest2;
}


.... where "i" in Rows["ArtikelName"] is the RowIndex, and ["ArtikelName"] the columnname (or integer columnindex).
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top