Retrieving single values from a DataGrid at RowIndex xy

Discussion in '.NET' started by voathun, Feb 7, 2010.

  1. voathun

    voathun

    Joined:
    Feb 7, 2010
    Messages:
    2
    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: Feb 7, 2010
    voathun, Feb 7, 2010
    #1
    1. Advertising

  2. voathun

    voathun

    Joined:
    Feb 7, 2010
    Messages:
    2
    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: Feb 7, 2010
    voathun, Feb 7, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Y2FydG1hbm4=?=

    read rowindex from gridview (template column)

    =?Utf-8?B?Y2FydG1hbm4=?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,562
    =?Utf-8?B?Y2FydG1hbm4=?=
    Oct 27, 2006
  2. DavidC

    Get GridView RowIndex

    DavidC, Mar 12, 2010, in forum: ASP .Net
    Replies:
    7
    Views:
    2,927
    DavidC
    Mar 14, 2010
  3. Marco Alting

    InsertRow() and rowIndex

    Marco Alting, Aug 19, 2003, in forum: Javascript
    Replies:
    3
    Views:
    279
    Marco Alting
    Aug 20, 2003
  4. webdev

    this.rowIndex question

    webdev, Oct 10, 2004, in forum: Javascript
    Replies:
    4
    Views:
    161
    webdev
    Oct 10, 2004
  5. AdamG
    Replies:
    13
    Views:
    274
    Michael Winter
    Dec 10, 2004
Loading...

Share This Page