Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Retrieving single values from a DataGrid at RowIndex xy

Reply
Thread Tools

Retrieving single values from a DataGrid at RowIndex xy

 
 
voathun voathun is offline
Junior Member
Join Date: Feb 2010
Posts: 2
 
      02-07-2010
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 by voathun; 02-07-2010 at 06:57 PM..
Reply With Quote
 
 
 
 
voathun voathun is offline
Junior Member
Join Date: Feb 2010
Posts: 2
 
      02-07-2010
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[i]["ArtikelName"].ToString();
rowtest2 = ds1.Tables[0].Rows[i]["Liefereinheit"].ToString();

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


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

Last edited by voathun; 02-07-2010 at 06:47 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView RowIndex DavidC ASP .Net 7 03-14-2010 01:10 PM
JSF Datatable rowindex issue gogaterpn Software 0 03-11-2009 01:28 PM
read rowindex from gridview (template column) =?Utf-8?B?Y2FydG1hbm4=?= ASP .Net 2 10-27-2006 07:39 AM
this.rowIndex question webdev Javascript 4 10-10-2004 07:32 PM
InsertRow() and rowIndex Marco Alting Javascript 3 08-20-2003 07:22 AM



Advertisments