Board index » cppbuilder » code request: Sort MainMenu
LarryJ
![]() CBuilder Developer |
LarryJ
![]() CBuilder Developer |
code request: Sort MainMenu2005-01-08 09:59:57 AM cppbuilder50 I am looking for code to sort the contents of a drop down menu in the TMainMenu. Does anyone have code for doing this they can send me? I would be very grateful. XXXX@XXXXX.COM Thanks. Larry Johnson |
JD
![]() CBuilder Developer |
2005-01-08 05:17:54 PM
Re:code request: Sort MainMenu
"LarryJ" < XXXX@XXXXX.COM >wrote:
Quote
using the IDE, then you can use the Menu Designer (right click the component) to drag the individual menu item to the desired location. If you are creating the menu or modifying the menu at runtime, then use the Insert method instead of the Add method so that you can keep the menu sorted as you go. If you have an MDI application and you want to do something with the MDIChild menus that get merged into the main form's menu, that's a bit different but basically the same concept of Insert(ing) them into the desired location. Sorting a menu is not too difficult to implement but why do you think that you need such a function? What exactly are you trying to accomplish under what circumstances? ~ JD |
LarryJ
![]() CBuilder Developer |
2005-01-09 03:31:52 AM
Re:code request: Sort MainMenu
I am using a menu that have all the drop down items dynamically created.
There can be items added and deleted to the menu. I need the menu in alphabetical order. The Insert method does not have a sort function. I still need the code to loop through the menu and figure out where to use Insert. So the question is how do I locate the correct position to insert a new menu item? Thanks Larry "JD" < XXXX@XXXXX.COM >wrote in message Quote
{smallsort} |
Kent
![]() CBuilder Developer |
2005-01-09 04:26:14 AM
Re:code request: Sort MainMenu
Why not try loading the menu captions in a TStringList
to handle the sorting, then repopulate the menu captions based on the TStringList sorted items? Kent |
JD
![]() CBuilder Developer |
2005-01-09 08:29:31 PM
Re:code request: Sort MainMenu
"LarryJ" < XXXX@XXXXX.COM >wrote:
Quote
function to accept as parameters, the menu items that is to be added and the menu item that it's being added to: //------------------------------------------------------------- void __fastcall TForm1::InsertMenuItem( TMenuItem *ParentItem, TMenuItem *ChildItem ) { bool Inserted = false; AnsiString ChildCaption = stripAmpersand( ChildItem->Caption ); for( int x = 0; x < ParentItem->Items->Count && !Inserted; ++x ) { AnsiString CurrentCaption = stripAmpersand( ParentItem->Items[x]->Caption ); if( AnsiCompareText(CurrentCaption, ChildCaption)>0 ) { ParentItem->Insert( x, ChildItem ); Inserted = true; } } if( !Inserted ) ParentItem->Add( ChildItem ); } //------------------------------------------------------------- AnsiString __fastcall TForm1::stripAmpersand( AnsiString s ) { int Pos = s.Pos("&"); if( Pos ) s.Delete( Pos, 1 ); return s; } //------------------------------------------------------------- ~ JD |
LarryJ
![]() CBuilder Developer |
2005-01-10 04:27:13 PM
Re:code request: Sort MainMenu |