Main Menu selet to Listview.

dashley

Well-known member
Joined
May 27, 2005
Messages
59
Location
Tennessee
Programming Experience
10+
I have a main menu on my form that (for the sake of keeping this explaination simple) has 3 sub items on my menu item "Select" main item

Litem10
Litem20
Litem30

If I select "Litem20" from the menu I want The code to take me to a listview I have on my form and highlight the listview item with the same name. My list view will have 70 plus items On it. I want them to be able to go to the menu and pick an item that is close to the desired item.

Any help will be greatly appreciated.

Thanks

Dan
 
Kulrom,

Opps, I may have over simplified my example. The sample you sent was great and I learned alot from it. My problem is I'm buiding the menu at runtime and I don't know what line item the menu is. Im running this code to make the sub items of the menu.

VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] FileLine [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String
[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] pre_FileLine [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String

[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] sr [/size][size=2][color=#0000ff]As[/color][/size][size=2] StreamReader = [/size][size=2][color=#0000ff]New[/color][/size][size=2] StreamReader("program files\pda_test_4\mtrxcat.txt") [/size][size=2][color=#008000]' CSV TXT FILE

[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myArray() [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String

[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] LV1 [/size][size=2][color=#0000ff]As[/color][/size][size=2] ListViewItem

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] Menux [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]Integer

[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] item_text [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String

[/color][/size][size=2]Menux = 1

[/size][size=2][color=#0000ff]While[/color][/size][size=2] sr.Peek > 0

FileLine = (sr.ReadLine)

pre_FileLine = Replace((FileLine), Chr(34), " ")

myArray = pre_FileLine.Split(",")

[/size][size=2][color=#0000ff]If[/color][/size][size=2] UBound(myArray) >= 2 [/size][size=2][color=#0000ff]Then

[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] menuitem(Menux) [/size][size=2][color=#0000ff]As[/color][/size][size=2] MenuItem

menuitem(Menux) = [/size][size=2][color=#0000ff]New[/color][/size][size=2] MenuItem

[/size][size=2][color=#0000ff]Me[/color][/size][size=2].MenuItem1.MenuItems.Add(menuitem(Menux))

menuitem(Menux).Text = myArray(3)

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2]Menux = Menux + 1

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]While

[/color][/size]

Although i would be able to determine th count of menu items I can't see how I would, could , or should have that many hard coded sub menu items. I would have to have a sub for each item. I'm looking for a more dynamic way to accomplish this. I'm sorry if my example took you down the wrong path. I didnt think of using a sub for each menu item I guess because I knew about the absence of indexes for the menu.

I think I'm going to have to capture the meun text from the on_click event if thats possible and then work from there,.

If you have any idea on how to do that I'd sure be glad to hear it.

Thanks again

Dan
 
You'll have to excuse me if my answer sways a little from what you may have expected because I'm not sure that I'm understanding the question correctly.
please try to explain it as clearly as possible. Moreover, please simplify the question tell me what you want to do with your app (purpose and stuff) and i'll try to help you out ... actually, i'm pretty sure we will find proper solution for you.

Cheers ;)

edit: i couldn't resist ... your code doesn't tell me much about your intention :( ... and ones again, can you tell me more about the purpose/use of the certain app ... it will help me most of all ;)
 
Last edited:
Kulrom,

Hi. I'm sorry about the confusion.

The app is destined for medical/nursing students. It will be written for desktop, internet and PDA (Palm & window ce) use.

I have a listview containing a multitude of possible medical actions. The listview will contain between 50 to 100+ items depending on the type of student.
To make it easier on the student a menu will be present that will have a list of major categories. This list will be from 12-18 items in length and is constructed using the code above.

I want to be able to bring up the menu and select a major category and the have it find that same categorie on the listview and go to it (Highlight it if possible).



Example Menu

Head
Chest ** user click on Chest on the menu
Abdomin



Example listview

Head
ear
nose
mouth
Chest ** listview brings this item to the top of the list (highlighted or not)
Heart
Lungs
Ribs
Abdomin
Stomach
Liver
Kidney


I hope this helps clear up what I'm trying to do.


Thanks Again

Dan
 
I think we have been very close to doing this same thing ... btw, it really doesn't matter the way how the items are added to mainmenu ... from CSV or any other datasource
cuz we gonna make it a little tricky declaring a function that will accept any mainmenu item and pass its text property to the search function ... but all that tomorow as not i'm very sleepy .. i gotta go ... Cheers ;)
 
Kulrom,

One of the main reasons is DB licensing. One destination of this code is for a windows CE (.net compact framework [im aware there a forum for it]) PDA. There are some issues with sqlserver CE . Another is retrofitting this code to earlier PDA's. There are far to may devices relying on the CSV files right now to change in mid stream. One of our long term goals will be to use web services and XML. MY marching orders right now are to stay with the CSV files. The plus for them is that there small and compact and rarely brake.



Dan
 
Kulrom,

Well I have half the problem solved - the part that tells me what menu item was clicked. Now all I have to do is get the listbox to go to it.

Dan


Dim handlerFile As EventHandler
handlerFile = New EventHandler(AddressOf MenuItemFileClick)


Dim m1 As New MenuItem("TEXT1", handlerfile)
Dim m2 As New MenuItem("TEXT2", handlerfile)
Me.mnuMain.MenuItems.Add(m1)
Me.mnuMain.MenuItems.Add(m2)

Private Sub MenuItemFileClick(ByVal sender As Object, ByVal e As EventArgs)

dim whereamI as string
dim oMenuItem as MenuItem
oMenuItem = CType(sender, MenuItem)

whereami = omenutem.text


end sub
 
Back
Top