New topic: Adding a Popup Menu to a List Box
<http://forums.realsoftware.com/viewtopic.php?t=29230> Page 1 of 1 [ 6 posts ] Previous topic | Next topic Author Message Jason_Adams Post subject: Adding a Popup Menu to a List BoxPosted: Sat Jul 25, 2009 11:40 pm Joined: Fri Nov 10, 2006 4:10 pm Posts: 461 I know I've seen this done -- in one form or another -- wherein a Popup Menu is added to all rows within a particular column of a List Box. It doesn't make a difference to me if this is actually accomplished using that specific control: I merely want the user to select a string from a list in a List Box, rather than typing in the text like a normal editable field. I've been looking around the List Box in the User's Guide and LR for awhile now but can't figure where to interject this sort of functionality. Can someone please point me in the right direction? Thanks! _________________ Vista Home Premium RB Pro 2009r3 "Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton Top Jonathon Post subject: Re: Adding a Popup Menu to a List BoxPosted: Sat Jul 25, 2009 11:47 pm Joined: Fri Sep 30, 2005 5:54 pm Posts: 1764 Location: Great Falls, Montana USA The ListBox has it own popup menu event! I found that out just in my last posting on here. Go to the LR and read on ConstructContextualMenu and ContextualMenuAction! I missed it the first time myself. Here's a simple code for both. ListBox.ContructContextualMenu: Code:dim NewChild As MenuItem NewChild=new MenuItem NewChild.Name="Copy" NewChild.Text="Copy" base.append NewChild NewChild=new MenuItem NewChild.Name="Paste" NewChild.Text="Paste" base.append newChild return True ListBox.ContextualMenuAction: Code:Dim c as New Clipboard If hitItem.Text = "Copy" then Main.TransEntry.CellType(Main.TransEntry.ListIndex, 1)=Listbox.TypeEditable Main.TransEntry.EditCell(Main.TransEntry.ListIndex, 1) Main.TransEntry.ActiveCell.Copy c.close ElseIf hitItem.Text="Paste" then Main.TransEntry.CellType(Main.TransEntry.ListIndex, 1)=Listbox.TypeEditable Main.TransEntry.EditCell(Main.TransEntry.ListIndex, 1) Main.TransEntry.ActiveCell.Paste c.close End Hope it helps? _________________ Jonathon Software Devlopement: http://www.medalertpc.com Surplus Hardware: http://www.semielectronics.com RB2005 R4 Pro for Windows XP Pro/SP2 Top Jason_Adams Post subject: Re: Adding a Popup Menu to a List BoxPosted: Sun Jul 26, 2009 12:23 am Joined: Fri Nov 10, 2006 4:10 pm Posts: 461 Thanks Jonathon! I thought there was a way to introduce the popup control, or at least appearance thereof, to the List Box, but I guess not. Creating a contextual menu instead is a reasonable alternative, though. Am I correct in thinking that when the cell is clicked on, the row and column index are stored, the contextual menu is produced and displayed, and the returned string is placed within said cell? I guess my only curiosity is how the contextual menu is fired upon a left-click. Thanks again for the direction! _________________ Vista Home Premium RB Pro 2009r3 "Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton Top Jonathon Post subject: Re: Adding a Popup Menu to a List BoxPosted: Sun Jul 26, 2009 12:29 am Joined: Fri Sep 30, 2005 5:54 pm Posts: 1764 Location: Great Falls, Montana USA Jason, You still can add a popumenu if you want! Infact what I gave you is a popmenu just for the ListBox. Look under Popmenu in the LR for more info! This one can be added to editfileds and the like:) EDIT: YES as the Contextual part means the use of the othere mouse button(Right Button) and yes as when you click on a cell, it knows where to put all the info into from the ContestualMenu upon the ContextualMenuAction event. ContextualMenuAction: Code:Main.TransEntry.EditCell(Main.TransEntry.ListIndex, 1)In my code, this means the following: Main[Window].TranEntry[Listbox].EditCell[ListBox Method](Main[Window].TranEntry[Listbox].ListIndex[The clicked Cell].1[Column 1, change this to the column of your choice]) _________________ Jonathon Software Devlopement: http://www.medalertpc.com Surplus Hardware: http://www.semielectronics.com RB2005 R4 Pro for Windows XP Pro/SP2 Last edited by Jonathon on Sun Jul 26, 2009 12:41 am, edited 1 time in total. Top Karen Post subject: Re: Adding a Popup Menu to a List BoxPosted: Sun Jul 26, 2009 12:36 am Joined: Fri Sep 30, 2005 8:53 am Posts: 588 1) Just Draw A disclosure widget in CellBackgroundPaint in the cells you want it in 2) In CellClick if the X and Y are on or lose enough to your disclosure widget create a dynamic menu and display using : Item = menuItem.Popup(X,Y) Positioning it relative to the cell as you want 3) The Returned item is the selected menuitem or Nil if no selection as made or it was handled by an existing menuhandler 4) Do Chosesn Action and Return True If you want, you can package all of that in a nice neat reusable Listbox subclass created an event like ConstructPopup(theMenu as MenuItem, row as integer, column as integer) analogous to ConstructContextualMenu or any number of other ways. - Karen Top benb Post subject: Re: Adding a Popup Menu to a List BoxPosted: Sun Jul 26, 2009 2:11 am Joined: Tue Dec 19, 2006 2:03 pm Posts: 74 Location: Sydney, Australia Oi! Oi! Oi! Or you could try my Listbox Extras. It has a method for creating a popup menu. See my sig for the link. _________________ My RB classes: Ben's Listbox Extras - RB ListBox printing and more, StyleGrid and DataGrid printing modules Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 6 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
