S
Sameh Ahmed
Hello there
Need to create a context menu in runtime, everything is ok except that I
need to check if a menuitem called "whatever" already exists in the context
menu.
Below is the code I use that gives an "Object reference not set to an
instance of an object" error
Any ideas how I can do that.
====================================================
For Each lvitem In lv1.SelectedItems '''''Depending on the item in the
selected items i want to add a MenuItem
objecttypemulti = lvitem.Tag.ToString.Substring(3, 3) 'to determine to
object type so know which MenuItems are needed
Dim menuitemtocheck As MenuItem
If objecttypemulti = 3 Then
menuitemtocheck.Index = 0 '''''Trying to give a value for the menuitem
If CM_LV1.MenuItems.Contains(menuitemtocheck) = False Then '''''here the
error is raised, i need to do that so i don't add a MenuItem more then one
time
tt = CM_LV1.MenuItems.Add("first actions")
tt.MenuItems.Add("machine hopa", New System.EventHandler(AddressOf
Me.LV_MenuItem_restartmachine))
End If
ElseIf objecttypemulti = 0 Then
tt = CM_LV1.MenuItems.Add("other Actions")
tt.MenuItems.Add("action whatever")
End If
Next
====================================================
the purpose is to add "first actions" and "other actions" only once even if
the object type in repeated more then once in the listview selected items.
Thanks in advance
Regards
Sameh
Need to create a context menu in runtime, everything is ok except that I
need to check if a menuitem called "whatever" already exists in the context
menu.
Below is the code I use that gives an "Object reference not set to an
instance of an object" error
Any ideas how I can do that.
====================================================
For Each lvitem In lv1.SelectedItems '''''Depending on the item in the
selected items i want to add a MenuItem
objecttypemulti = lvitem.Tag.ToString.Substring(3, 3) 'to determine to
object type so know which MenuItems are needed
Dim menuitemtocheck As MenuItem
If objecttypemulti = 3 Then
menuitemtocheck.Index = 0 '''''Trying to give a value for the menuitem
If CM_LV1.MenuItems.Contains(menuitemtocheck) = False Then '''''here the
error is raised, i need to do that so i don't add a MenuItem more then one
time
tt = CM_LV1.MenuItems.Add("first actions")
tt.MenuItems.Add("machine hopa", New System.EventHandler(AddressOf
Me.LV_MenuItem_restartmachine))
End If
ElseIf objecttypemulti = 0 Then
tt = CM_LV1.MenuItems.Add("other Actions")
tt.MenuItems.Add("action whatever")
End If
Next
====================================================
the purpose is to add "first actions" and "other actions" only once even if
the object type in repeated more then once in the listview selected items.
Thanks in advance
Regards
Sameh