I've been trying to do some work with a datagrid control on a winform and
have gotten very frustrated with it. I need to be able to determine when
the user clicks on a given cell but can't find anything that seems to be
reliable.

The click and doubleclick events fire when the user clicks on the row or
column headers and *sometimes* when the user clicks on a particular cell. I
can't figure out any pattern to when it fires by clicking on a cell.

The CurrentCellChanged fires when the user clicks on a cell but ALSO when
the user clicks on a different row or column header so if they select a cell
and then click a column header to sort differently then it changes the
selection. I need to identify the last cell selected only and not have it
be affected by row or column clicks.

There are a lot of other things that should be simple that the datagrid
seems to make as difficult as possible but I've managed to work around
everything so far except the ability to select a cell. Any ideas will be
appreciated.

--
C# newbie... posts are probably inaccurate, inelegant or both

Re: Datagrid frustartions by Dmitriy

Dmitriy
Fri Jan 23 02:37:35 CST 2004

Hello Bill,

Use the MouseUp event (or MouseDown, depending on what you want to do upon a
click) and then use the HitTest method on the grid instance to determine
whether the user has clicked on a cell, on a row header, on a column header
etc.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Bill Styles" <noemail@nowhere.com> wrote in message
news:%23Ow2gET4DHA.1816@TK2MSFTNGP12.phx.gbl...
> I've been trying to do some work with a datagrid control on a winform and
> have gotten very frustrated with it. I need to be able to determine when
> the user clicks on a given cell but can't find anything that seems to be
> reliable.
>
> The click and doubleclick events fire when the user clicks on the row or
> column headers and *sometimes* when the user clicks on a particular cell.
I
> can't figure out any pattern to when it fires by clicking on a cell.
>
> The CurrentCellChanged fires when the user clicks on a cell but ALSO when
> the user clicks on a different row or column header so if they select a
cell
> and then click a column header to sort differently then it changes the
> selection. I need to identify the last cell selected only and not have it
> be affected by row or column clicks.
>
> There are a lot of other things that should be simple that the datagrid
> seems to make as difficult as possible but I've managed to work around
> everything so far except the ability to select a cell. Any ideas will be
> appreciated.
>
> --
> C# newbie... posts are probably inaccurate, inelegant or both
>


Re: Datagrid frustartions by Bill

Bill
Fri Jan 23 08:10:06 CST 2004

"Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.com> wrote
in message news:uNQ2hwY4DHA.1704@tk2msftngp13.phx.gbl
> Hello Bill,
>
> Use the MouseUp event (or MouseDown, depending on what you want to do
> upon a click) and then use the HitTest method on the grid instance to
> determine whether the user has clicked on a cell, on a row header, on
> a column header etc.

Excellent, thanks! That appears to be a viable option from the quick tests
I just did. Now I can create a wrapper that provides the events I really
need.


--
C# newbie... posts are probably inaccurate, inelegant or both