7 Replies - 494 Views - Last Post: 14 March 2012 - 11:39 AM Rate Topic: -----

#1 hondakillrsx  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

pulling data value from DataGrid

Posted 10 March 2012 - 08:11 PM

Hey guys,
I have a form with a datagrid called dataSetGridView1 that queries from a mysql database. I need to be able to click on any of the rows and have the "ID" column populate to the Text field below the grid. I have this working some of the time with the following code:


private void dataSetGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
                return;

            string id;
           id = dataSetGridView1.Rows[e.RowIndex].Cells[0].Value + "";          
            box1.Text = id;




I have looked and searched every where as to why the text box only populates some of the time and can't seem to come up with an answer. Can someone help! Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: pulling data value from DataGrid

#2 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: pulling data value from DataGrid

Posted 11 March 2012 - 05:52 AM

I think yo must change OrElse '||' to AndAlso '&&' to get what you want.
            if (e.RowIndex < 0 && e.ColumnIndex < 0)
                return;

Was This Post Helpful? 0
  • +
  • -

#3 hondakillrsx  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

Re: pulling data value from DataGrid

Posted 11 March 2012 - 09:22 AM

View Postsela007, on 11 March 2012 - 05:52 AM, said:

I think yo must change OrElse '||' to AndAlso '&&' to get what you want.
            if (e.RowIndex < 0 && e.ColumnIndex < 0)
                return;


Nope, still getting the same issue. It's weird because I can't figure out why it works sometimes and why it doesn't others. If I knew that I could probably come up with the solutions. I've been clicking for hours trying to find a pattern....
Was This Post Helpful? 0
  • +
  • -

#4 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: pulling data value from DataGrid

Posted 11 March 2012 - 09:29 AM

oh,,,you have put code in the cell content click.. put your code in 'cell click event'

Cell content click is raised only when you click on the content of the cell(letter, number, image)..
Was This Post Helpful? 1
  • +
  • -

#5 hondakillrsx  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

Re: pulling data value from DataGrid

Posted 12 March 2012 - 04:41 PM

View Postsela007, on 11 March 2012 - 09:29 AM, said:

oh,,,you have put code in the cell content click.. put your code in 'cell click event'

Cell content click is raised only when you click on the content of the cell(letter, number, image)..


Ok so this worked, sort of. It works every time now, but only on certain columns (to be specific, the Title column and the Description column). The ones that don't work are the "Platform" column and the "Version" column. Is there an event for "highlighted" instead of clicked? If not, Is there a way to have the GridView not default and highlight the first row?
Was This Post Helpful? 0
  • +
  • -

#6 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: pulling data value from DataGrid

Posted 13 March 2012 - 12:51 AM

Quote

The ones that don't work are the "Platform" column and the "Version" column.

There is also MouseClick event you can try that.

Quote

Is there an event for "highlighted" instead of clicked?

for "highlighted" you can use Selectionchanged.

Quote

Is there a way to have the GridView not default and highlight the first row?
You can 'un-highlight' first row by yourself.
Was This Post Helpful? 0
  • +
  • -

#7 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,673
  • Joined: 24-August 11

Re: pulling data value from DataGrid

Posted 13 March 2012 - 12:16 PM

If you want to be able to click anywhere in the cell, try adding

protected void dataSetGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(dataSetGridView1, "Select$" + e.Row.RowIndex);
}


Was This Post Helpful? -1
  • +
  • -

#8 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: pulling data value from DataGrid

Posted 14 March 2012 - 11:39 AM

View Posth4nnib4l, on 13 March 2012 - 03:16 PM, said:

If you want to be able to click anywhere in the cell, try adding

protected void dataSetGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(dataSetGridView1, "Select$" + e.Row.RowIndex);
}



His code is for WinForms, as noted by the DataGridViewCellEventArgs. There is no DataGridView in ASP.Net.

There are also the CellClick and CellMouseClick events you could use.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1