Question about the scroll arrows in DataGrid

G

Guest

hello
i have a DataGrid table and by the help of Adnan, here in the forum, i have the Mouse_up Event that by Clicking a row on the dataGrid it's selectes the whole ro
the problem is when i'm pressing the scroll arrows (to move the rows up\down\left\right) the whole stays selected except the cell which i pressed
how can i prevent that from hapenning

here with the Mouse_Up method

private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e

m_X=e.X
m_Y=e.Y
DataGrid myGrid = (DataGrid)sender
DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X, e.Y)
if (myHitInfo.Type == DataGrid.HitTestType.Cell || myHitInfo.Type == DataGrid.HitTestType.RowHeader

myGrid.Select(myHitInfo.Row)
myGrid.CurrentRowIndex = myHitInfo.Row
int someSampleID = Convert.ToInt32(myGrid[myHitInfo.Row,0])



thank you all
Gid
 
N

Nicholas Paldino [.NET/C# MVP]

Gidi,

The HitTest class doesn't seem to have information about scroll bars, so
I think you have to determine that yourself. Basically, what you want to do
is find out how wide the scroll bar is (or guess). Once you have that, in
the mouse up event, check to see if the number of visible rows is less than
the number of rows available. If this is the case, the scroll bar is being
shown, and you should not select the row if the x coordinate falls within
the boundary on the right side of the screen where the scrollbar would be.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Gidi said:
hello,
i have a DataGrid table and by the help of Adnan, here in the forum, i
have the Mouse_up Event that by Clicking a row on the dataGrid it's selectes
the whole row
the problem is when i'm pressing the scroll arrows (to move the rows
up\down\left\right) the whole stays selected except the cell which i
pressed.
how can i prevent that from hapenning?

here with the Mouse_Up method:

private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
m_X=e.X;
m_Y=e.Y;
DataGrid myGrid = (DataGrid)sender;
DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X, e.Y);
if (myHitInfo.Type == DataGrid.HitTestType.Cell || myHitInfo.Type ==
DataGrid.HitTestType.RowHeader )
{
myGrid.Select(myHitInfo.Row);
myGrid.CurrentRowIndex = myHitInfo.Row;
int someSampleID = Convert.ToInt32(myGrid[myHitInfo.Row,0]);
}
}

thank you all,
Gidi
 

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

Top