how to find the rowindex in datagridviow

Posted by Santosh4u under VB.NET on 7/11/2011 | Points: 10 | Views : 12769 | Status : [Member] | Replies : 10
hi

any body plz tell me,how to find the rowindex of a gridviw in MouseClick event for windows application.

Regards
Santosh




Responses

Posted by: Ndebata on: 7/11/2011 [Member] Starter | Points: 25

Up
0
Down
http://www.dotnetfunda.com/codes/code1575-getting-row-or-rowindex-from-the-event-of-control-placed-inside-a-grid.aspx
Then you can use
currentgridrow.RowIndex


Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 7/11/2011 [Member] Starter | Points: 25

Up
0
Down
If you want to get using javascript, read this http://www.itfunda.com/how-to-get-the-primary-key-value-of-the-gridview-rows-in-javascript/Free/153.

Thanks

Regards,
Raja, USA

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u_6178 on: 7/11/2011 [Member] Starter | Points: 25

Up
0
Down
you can also refer the following link:
http://bshouman.blogspot.com/2008/03/get-gridviewrows-index-on-button-click.html

Thanks & Regards,

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santosh4u on: 7/11/2011 [Member] Bronze | Points: 25

Up
0
Down
hi All
i want it for windows application gridview.....
but ur code will be applicable for web application gridview

Regards
santosh

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 7/11/2011 [Member] Starter | Points: 25

Up
0
Down
Try to use Cell Click event of datagrid
c#
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

{
if(e.RowIndex>=0 && e.ColumnIndex>=0)
MessageBox.Show(string.Format("Row Index:{0}, Column Index:{1}", e.RowIndex, e.ColumnIndex));
}

VB
Private Sub dataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs)

If e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 Then
MessageBox.Show(String.Format("Row Index:{0}, Column Index:{1}", e.RowIndex, e.ColumnIndex))
End If
End Sub


I am confiused with your wording "GRDVIEW ".

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 7/11/2011 [Member] [MVP] Bronze | Points: 25
Posted by: RaviRanjanKr on: 7/11/2011 [Member] Starter | Points: 25

Up
0
Down
At CellEnter event of DataGridView use given code to find out Index

string text = dataGridView1.Rows[e.RowIndex].Cells["ColumnName"].Value.ToString();


Thanks
Ravi Ranjan Kumar
http://raviranjankr.wordpress.com

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santosh4u on: 7/11/2011 [Member] Bronze | Points: 25

Up
0
Down
hi all
i can find the rowindex in cell_enter,cell_click etc...
but i want it in mouseclick event...
so plz post the code to find rowindex in mouseclick event..

Regards
santosh



Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 7/12/2011 [Member] Starter | Points: 25

Up
0
Down
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)

{
int _theight = 0;
string _Location = "";
if (e.Y >= _theight && e.Y <= _theight + dataGridView1.ColumnHeadersHeight)
_Location= "Header";
else
{
_Location = "";
_theight = _theight + dataGridView1.ColumnHeadersHeight;
foreach (DataGridViewRow item in dataGridView1.Rows)
{
if (e.Y >= _theight && e.Y <= _theight + item.Height)
{
_Location = "Row Index: " + item.Index;
break;
}
else
_theight = _theight + item.Height;
}
if(_Location== "")
_Location="Outside";
}
MessageBox.Show(_Location);
}



Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 7/12/2011 [Member] Starter | Points: 25

Up
0
Down

Login to post response