Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » detecting clicked row in ArrayCtrl [FIXED...]
detecting clicked row in ArrayCtrl [FIXED...] [message #2014] Wed, 29 March 2006 21:55 Go to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
I have an ArrayCtrl and would like to take some action when a row is clicked. It is easy to assign a callback to WhenLeftClick. But the callback should find out which row was clicked. GetCursor is not good enough, because the click could be below the last row, and the cursor is not moved then, so it would appear as if the user clicked the row which has the cursor.

[Updated on: Sun, 09 April 2006 03:58] by Moderator

Report message to a moderator

Re: detecting clicked row in ArrayCtrl [message #2018 is a reply to message #2014] Wed, 29 March 2006 23:22 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
hojtsy wrote on Wed, 29 March 2006 14:55

I have an ArrayCtrl and would like to take some action when a row is clicked. It is easy to assign a callback to WhenLeftClick. But the callback should find out which row was clicked. GetCursor is not good enough, because the click could be below the last row, and the cursor is not moved then, so it would appear as if the user clicked the row which has the cursor.


Interesting trouble.... I guess it will require another interface improvement... (I guess WhenLeftClick only for items and WhenLeftClickNoItem for "free" area with default proxy to WhenLeftClick?)

Mirek
Re: detecting clicked row in ArrayCtrl [message #2029 is a reply to message #2018] Thu, 30 March 2006 08:54 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
How about ArrayCtrl with NoCursor? Is the cursor field updated to the last clicked row in this case, so that I can read it from WhenLeftClick action?
What if I want to take some action on middle button click?
I think a more generic solution would be something like a WhenClicked action which gets the mouse position in parameter, and would have a default proxy to WhenBar & WhenLeftClick & WhenLeftDouble.
Re: detecting clicked row in ArrayCtrl [message #2049 is a reply to message #2029] Thu, 30 March 2006 22:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
hojtsy wrote on Thu, 30 March 2006 01:54

How about ArrayCtrl with NoCursor? Is the cursor field updated to the last clicked row in this case, so that I can read it from WhenLeftClick action?
What if I want to take some action on middle button click?
I think a more generic solution would be something like a WhenClicked action which gets the mouse position in parameter, and would have a default proxy to WhenBar & WhenLeftClick & WhenLeftDouble.



Well, I believe that if your code depends on actual mouse position, it is much better to simply derive ArrayCtrl and override LeftDown....

In other words, following this path, we would ended with callbacks for each single virtual method of Ctrl.

Mirek
Re: detecting clicked row in ArrayCtrl [message #2056 is a reply to message #2049] Thu, 30 March 2006 22:40 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
I can hardly imagine an ArrayCtrl where you are interested in left clicks but not the position of them. At least you would be interested in the clicked row index, but adding column index too could not hurt. Since the clicked row is not always available through GetCursor (clicks below last row), would I need to subclass ArrayCtrl just to do exactly the thing that WhenLeftClick callback is for? How about adding a GetClickPosition() public method, which the WhenLeftClick can call?
Re: detecting clicked row in ArrayCtrl [message #2058 is a reply to message #2056] Thu, 30 March 2006 22:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
hojtsy wrote on Thu, 30 March 2006 15:40

I can hardly imagine an ArrayCtrl where you are interested in left clicks but not the position of them. At least you would be interested in the clicked row index, but adding column index too could not hurt. Since the clicked row is not always available through GetCursor (clicks below last row), would I need to subclass ArrayCtrl just to do exactly the thing that WhenLeftClick callback is for? How about adding a GetClickPosition() public method, which the WhenLeftClick can call?


I believe there is only a little difference between this and my original "WhenLeftClickNoItem" suggestion - as long as your are not interested in "non-existing" (past the last row) rows (which I believe you should not be).

I mean - WhenLeftClickNoItem -> indicates click outside

WhenLeftClick -> indicates click inside, use GetCursor to get row, GetClickColumn to get column.

Mirek

P.S.: would it be based on my actual experience, I would remove almost all ArrayCtrl callbacks except of WhenCursor, WhenLeftDouble (maybe add WhenLeftDoubleNoItem) and WhenBar. I have not used others for years....
Re: detecting clicked row in ArrayCtrl [message #2062 is a reply to message #2058] Fri, 31 March 2006 08:22 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
luzr wrote on Thu, 30 March 2006 15:57

I believe there is only a little difference between this and my original "WhenLeftClickNoItem" suggestion - as long as your are not interested in "non-existing" (past the last row) rows (which I believe you should not be). WhenLeftClick -> indicates click inside, use GetCursor to get row, GetClickColumn to get column.
I am indeed not interested in clicks on non-existent rows. But can I use GetCursor if the ArrayCtrl is set to not display the cursor? If yes then "WhenLeftClickNoItem" suggestion is OK.
luzr wrote on Thu, 30 March 2006 15:57


would it be based on my actual experience, I would remove almost all ArrayCtrl callbacks except of WhenCursor, WhenLeftDouble (maybe add WhenLeftDoubleNoItem) and WhenBar. I have not used others for years....
Actually I am trying to use WhenLeftDouble. I was just thinking that refering to WhenLeftClick would simplify the discussion. None of my current apps use the callbacks you are mentioned as removal-candidates, but I suppose there may be other apps out there which does.
Re: detecting clicked row in ArrayCtrl [message #2063 is a reply to message #2056] Fri, 31 March 2006 09:50 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
hojtsy wrote on Thu, 30 March 2006 15:40

I can hardly imagine an ArrayCtrl where you are interested in left clicks but not the position of them. At least you would be interested in the clicked row index, but adding column index too could not hurt. Since the clicked row is not always available through GetCursor (clicks below last row), would I need to subclass ArrayCtrl just to do exactly the thing that WhenLeftClick callback is for? How about adding a GetClickPosition() public method, which the WhenLeftClick can call?


OK, after some thinking, I agree, now on uvs2:

ArrayCtrl::
	Point      GetClickPos() const;
	int        GetClickColumn() const;
	int        GetClickRow() const;


Mirek
Previous Topic: edit data in arrayctrl [GOOD EXAMPLES...]
Next Topic: how to use ArrayCtrl.SetLineCy(int,int)?
Goto Forum:
  


Current Time: Sat Apr 20 04:10:54 CEST 2024

Total time taken to generate the page: 0.02439 seconds