 |
|
 |
Hi Daniel Presman!
I readed your's code a bout menu dynamic. But I understand the example how do works when i want to change other user.
I try change user, then click fill It happened error:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll
Additional information: Specified argument was out of the range of valid values.
If sel_key.LastIndexOf(".") >= 0 Then
sel_KeyParent = sel_key.Substring(0, sel_key.LastIndexOf("."))
parentItem = HashMenu(sel_KeyParent)
parentMenu = parentItem.MenuItemobj
parentMenu.MenuItems.Add(sonMenu) Else
Me.MainMenu.MenuItems.Add(sonMenu)
parentMenu = sonMenu
End If
Thanks !
like vb.net very much, but i'm begining studieds vb.net
|
|
|
|
 |
|
 |
I guess you should have to clear all hashtables before changing user.
When I wrote the code to this example, it was a simple exmaple and I did not think about changing user.
Try doing that, Ihope it will work.
Daniel
|
|
|
|
 |
|
 |
Thank you for your about
However,I tried your's suggest:
In Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
I've add code by two the way:
+ The fisrt:I Add code: Dim nCount As Integer
Dim i As Integer
nCount = Me.MainMenu.MenuItems.Count()
If nCount > 0 Then
For i = nCount - 1 To 0 Step -1
Me.MainMenu.MenuItems.Remove(Me.MainMenu.MenuItems.Item(i))
Next
End if
If LoadUserPerms() = False Then
MsgBox("Username or Password are incorrect")
Else
LoadMenuItems()
End If
End Sub
It work have happen error which i send to you
The two way I add Code
HashFunctions.Clear()
If LoadUserPerms() = False Then
MsgBox("Username or Password are incorrect")
Else
LoadMenuItems()
End If
It work have happen error:
If sel_key.LastIndexOf(".") >= 0 Then
sel_KeyParent = sel_key.Substring(0, sel_key.LastIndexOf"."))
parentItem = HashMenu(sel_KeyParent)
parentMenu = parentItem.MenuItemobj
parentMenu.MenuItems.Add(sonMenu)
Else
Me.MainMenu.MenuItems.Add(sonMenu)
parentMenu = sonMenu
End If
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll
Additional information: Specified argument was out of the range of valid values.
I hope that you can help me.
Thanks!
like vb.net very much, but i'm begining studieds vb.net
|
|
|
|
 |
|
 |
I guess, that in order to change user You should clean every object.
This is a short code to clean the menu and build a new one with a new username:
'Clean the previous menu items and hashtables
MainMenu.MenuItems.Clear()
HashFunctions.Clear()
HashMenu.Clear()
'select user parameters from the database
'(since I am sure there is a user 1 and 2 I am not checking
' here if it exists, but you should check)
Dim adap As New OleDb.OleDbDataAdapter("", conn)
adap.SelectCommand.CommandText = "SELECT * FROM ITEMS INNER JOIN PERMS ON PERMS.ID_ITEM = ITEMS.ID_ITEM WHERE ID_USER =" & user_id
dsUser.Clear()
adap.Fill(dsUser)
'Load new menu items to main menu
LoadMenuItems()
Hope this helps,
Daniel
|
|
|
|
 |
|
 |
Hi !Daniel Presman
Thank you very much, I tried examples, it worked right. I'm researching how call function or call *.dll, and drawing icon for items.
I hope that, if i have trouble you will help me.
Sorry,my English very bad so that if i talk to you, you can't understand my verbalision. I hope that with the time my English is improving and i can to explain
Thanks,
Goog Luck!
like vb.net very much, but i'm begining studieds vb.net
|
|
|
|
 |
|
 |
I've try the dynamic nemu but i have a problem :
* In my ITEM - table :
name - hearar - text
-----------------------------
Master - 0 - Master
Polis - 0.1 - Polis
member - 0.2 - Member
Underwritng - 1 - UNDERWITTING
Claim - 2 - Claim
Finance - 3 - Finance
Report - 4 - Report
Utility - 5 - Utility
Exit - 6 - Exit
But when I run the programme, output of menu is :
Master Underwriting exit Report Utility
According the number of hearar what I want is :
Master Underwriting Report Utility Exit
How can I have the menu text index that I want,.. is there any solution... help me please..
|
|
|
|
 |
|
 |
Take a look at the messages about the order of items.
Daniel
|
|
|
|
 |
|
 |
How I can keep the order that I save in the field Hierar ?
I don't understand what kind of order is displayed
Thank you
pietrorrrago
|
|
|
|
 |
|
 |
I am wondering as well how the order of the items works out. Also, in the Access database, the table ITEMS has an IMG field. I am assuming this is for an image, please give details on this one.
Paul
|
|
|
|
 |
|
 |
Hi Paul,
It is possible to order the items, with an order by in the select command or after the data is in the dataset.
The IMG is here because when I did it I also made a 'Favorites' feature. User can create buttons to link him to his most used functinons and those buttons have images.
It is also possible to put images on the menu Item. One option in th C1 components for menu.
Daniel
|
|
|
|
 |
|
 |
Daniel Presman wrote: an order by in the select command
I've done that with ORDER BY HIERAR and it still wants to place menu items in whatever order that it pleases...I've tried with both select statements...any thought?
Paul
|
|
|
|
 |
|
 |
Daniel,
Here is a dump of the ITEMS table I have...
ID_ITEM NAME HIERAR TEXT DESC IMG FUNC
13 File 2 File File Menu FileStatus
14 New 2.1 New New File FileNew
15 Open 2.2 Open Open File FileOpen
16 Edit 1 Edit Edit Menu EditStatus
17 Copy 1.1 Copy Copy From Clipboard EditCopy
18 Tools 3 Tools Tool Menu ToolStatus
19 Draw 3.1 Smart Draw Invoke Smart Draw GoSmart
20 Foo 0 Foo Foo Menu Foo
And the menu bar I see is in the order of:
Foo Edit File Tools
which is the correct order
Paul
|
|
|
|
 |
|
 |
What did you change?
|
|
|
|
 |
|
 |
What did I change? Strangely or (maybe) disturbingly nothing.
|
|
|
|
 |
|
 |
Daniel,
I think may have found what could be causing the hierarchy ordering problem. In your database, if you log in as the user Debora Presman, according to the PERMS table, only items 4, 5, 7, and 8 are visible. It so happens that items 7 and 8 are the children of item 6 - 'Window'. This for some reason causes 'File', which has a HIERAR value of 0 to come up afterward.
I hope this sheds some light on this.
Paul
|
|
|
|
 |
|
 |
It seems to me that the problem is that the hash table does not follow the order you add the items to it, but either has a collections of pairs to get by Key, and the first order is then not important.
We should create another structure, between the Hashtable and the Menu, to get the Items from the HashTable, order them in whatever order we want and them put it on the menu.
I have to think about it a little. Any ideas?
Daniel
|
|
|
|
 |
|
 |
Daniel,
I will give it some thought and relay any ideas to you.
Paul
|
|
|
|
 |
|
 |
I've solved in this way:
Dim d As DictionaryEntry
Dim parentMenu As New MenuItem
Dim sonMenu As New MenuItem
Dim parentItem As New DinamicMenu
Dim sonItem As New DinamicMenu
Dim sel_key, sel_KeyParent As String
'For Each d In HashMenu
' sonItem = d.Value
' sel_key = d.Key
' 'MsgBox(sonItem.Text & " - " & sel_key)
' sonMenu = sonItem.MenuItemobj
' If sel_key.LastIndexOf(".") >= 0 Then
' sel_KeyParent = sel_key.Substring(0, sel_key.LastIndexOf("."))
' parentItem = HashMenu(sel_KeyParent)
' parentMenu = parentItem.MenuItemobj
' parentMenu.MenuItems.Add(sonMenu)
' Else
' Me.MainMenu.MenuItems.Add(sonMenu)
' End If
'Next
'--------------------
Dim loop_hierar As String
For i = 0 To dsUser.Tables(0).Rows.Count - 1
loop_hierar = dsUser.Tables(0).Rows(i)("Hierar")
For Each d In HashMenu
sonItem = d.Value
sel_key = d.Key
If loop_hierar = d.Key Then
sonMenu = sonItem.MenuItemobj
If sel_key.LastIndexOf(".") >= 0 Then
sel_KeyParent = sel_key.Substring(0, sel_key.LastIndexOf("."))
parentItem = HashMenu(sel_KeyParent)
parentMenu = parentItem.MenuItemobj
parentMenu.MenuItems.Add(sonMenu)
Else
Me.MainMenu.MenuItems.Add(sonMenu)
End If
End If
Next
Next
Is not elegant but works, the number of items of my menu are more then 10 and so I've changed the structure of hierar field from 1.2.1 in 01.02.01 because otherwise the order was 1,10,11,2,...
but .... now don't works the calling of the associate function ... need more work
|
|
|
|
 |
|
 |
Great job.
About the functions:
In my case, I have created Dlls with classes as userControls. On the database, each menu item is associated to a dll and to a class (control).
I created a panel in my main form. Every time user clicks on menu, the application checks on the database wich dll to open and wich userControl to create. Then create an instance of the control and add it to the main form panel.
Something like that (on the CallForMenuItem sub):
'Get the dll and class of control to load to main form
'format dllname*classname
funcToCall = HashFunctions(position)
'create the control to load to main Panel
Dim o, s As Object
Dim AssemblyDll, ClassDll As String
AssemblyDll = funcToCall.substring(0,funcToCall.indexOf("*"))
Classe = funcToCall.substring(funcToCall.indexOf("*") + 1)
o = Activator.CreateInstance(AssemblyDll, AssemblyDll & "." & Classe)
s = o.Unwrap()
Me.mainPanel.Controls.Add(s)
|
|
|
|
 |
|
 |
Dear Daniel
I've try to rum the programme, but i have some problem :
- Classe (is not recognize)
dim classse as.....?
- AssemblyDll (error)
Because funcToCall.indexOf("*")) <0 (-1)
Please help me how to run this.
regards
Alex
|
|
|
|
 |
|
 |
I can´t understand your question?
Where is this line of code?
What is the error message?
Regards,
Daniel
|
|
|
|
 |
|
 |
Dear Daniel,.. Thank's for the information & the answer of my last question this the programme code that i try to run : ***************************************************** 'Get the dll and class of control to load to main form 'format dllname*classname funcToCall = HashFunctions(position) 'create the control to load to main Panel Dim o, s As Object Dim AssemblyDll, ClassDll As String AssemblyDll = funcToCall.substring(0,funcToCall.indexOf("*")) Classe = funcToCall.substring(funcToCall.indexOf("*") + 1) o = Activator.CreateInstance(AssemblyDll, AssemblyDll & "." & Classe) s = o.Unwrap() Me.mainPanel.Controls.Add(s) *************************************************** When run the programme, i've some message : -. Name 'classe' is not declared in this line programme stop an the message : AssemblyDll = funcToCall.substring(0,funcToCall.indexOf ("*")) - addtional information : lenght cannot less then zero Please help me,.. now I'm try to make database menu on my application regards Alex
|
|
|
|
 |
|
 |
change the word classe to ClassDll.
|
|
|
|
 |
|
 |
if you want to order item menu: You can add the code
Dim parentMenu As New MenuItem
Dim sonMenu As New MenuItem
Dim parentItem As New clsMenuDinamic
Dim sonItem As New clsMenuDinamic
Dim sel_key, sel_KeyParent As String
Dim al As ArrayList
al = New ArrayList(Hashmenu.Keys)
al.Sort()
Dim k As Integer
For k = 0 To al.Count - 1
For Each d In Hashmenu
If al(k) = d.Key Then
sonItem = d.Value
sel_key = d.Key
sonMenu = sonItem.MenuItemO
If sel_key.LastIndexOf(".") >= 0 Then
sel_KeyParent = sel_key.Substring(0, sel_key.LastIndexOf("."))
parentItem = Hashmenu(sel_KeyParent)
parentMenu = parentItem.MenuItemO
parentMenu.MenuItems.Add(sonMenu)
Else
Me.MainMenu.MenuItems.Add(sonMenu)
End If
End If
Next
Next
like vb.net very much, but i'm begining studieds vb.net
|
|
|
|
 |
|
 |
Use SortedList instead of HashTable to use the natural order.
Change the line:
Public HashMenu As New hashTable
to:
Public HashMenu As New SortedList
|
|
|
|
 |