Thanks for your suggestion. I'm new to OO and I think I was just over-complicating things! Regards SH
SerialHobbyist
Posts
-
Obtaining a reference to the TreeView item in a context menu -
Obtaining a reference to the TreeView item in a context menuI've created a TreeView which lists items from active directory. With the help of another Code Project user, I've created a context menu which is specific to the type of object right-clicked-on by the user. The problem is that when I select the menu option, the 'sender' holds a reference to the MenuItem, not the TreeNode clicked-on in the first place. How can I get a reference to the original TreeNode that the user right-clicked on? I've thought of one way but it seems a bit of a botch: to create a TaggedMenuItem class inherited from MenuItem which has a 'Tag' like Controls have and to use the MouseUp event and populate the Tag of EVERY TaggedMenuItem on the context menu with a reference to the TreeNode as I create the context menu. Then, I can get back to it from the menu item click event handler. Like I said, this sounds a bit crap. Is there a better way?
-
Context Menu in TreeView controlThanks very much. That sorted it out for me and I'm generating a context-specific menu.
-
Context Menu in TreeView controlI'm displaying a TreeView of an active directory domain. I want to right-click on a Node and display a context menu which has a submenu which is built depending on the type of object clicked on. I've created a context menu but when right-clicking on an object, this code, running in the Popup event of the context menu item which displays the sub-menu:
MenuItem directoryObjectClickedOn = (MenuItem)sender; ContextMenu cm = directoryObjectClickedOn.GetContextMenu(); TreeView ad = (TreeView)cm.SourceControl; DirectoryEntry aDObject = (DirectoryEntry)ad.SelectedNode.Tag; MessageBox.Show(aDObject.Name);
always gives me the previous object, not the current one. Any idea how to get the current object? -
Microsoft.Win32 NamespaceI'm a newbie so maybe this is a daft question but why do you need to? If you just put
Imports Microsoft.Win32
at the top of your class, does that do the trick?
-
How to cancel a form with a text box with the Leave Event codedMy New User form has a pair of text boxes used to define new users to my app. For both I've used the 'Leave' event to validate them before the form's OK button is enabled. (I've included the code for the simpler one of the two below.) I also want a Cancel button so that the user can choose not to set up a new user. At the mo, the Cancel button just sets DialogResult.Cancel. When the user clicks on the Cancel button the first time, the Leave event is still triggered and the users gets a "You must enter a name." message box. If the user clicks Cancel again, the window closes. I realise that I could do the checks when the user clicks OK but it seems 'more OO' to validate each box. How can I avoid this message box on cancel but still check the formatting when the user moves out of the text box otherwise?
Private Sub txtNewOppName_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles txtNewOppName.LeaveIf txtNewOppName.Text = "" Then Me.NameDefined = False MessageBox.Show("You must enter a name.") Me.Select() Else Me.NameDefined = True End If If Me.EmailDefined And Me.NameDefined Then Me.btnOk.Enabled = True End If
End Sub
-
how to code toolbar panels.No, you could use If...End If. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmSelectCase.asp I've assumed an Open button, a Save button and a SaveAs button. For the Open button, I've pointed it at what might be the routine you've already written to handle a traditional menu item called mnuFileOpen. Select Case toolbar.Buttons.IndexOf(e.button) Case 0 mnuFileOpen_Click(Nothing, Nothing) Case 1 SaveFile() Case 2 SaveFileAs() Case Else ' Other values. 'Since you should know how many buttons you've got, you shouldn't 'need a Case Else. End Select Don't forget that if you've used separators, they'll be on this list. E.g. If you have a separator after the Open button, you should code: Case 1 Case 2 SaveFile() etc.
-
TextBox / RichTextBox - displaying the endYou star! Thanks very much.
-
how to code toolbar panels.When you click on a toolbar, the toolbar's ButtonClick event is fired and the button that was click is passed in ToolBarButtonClickEventArgs - its button property contains the index of the button (from the Buttons collection). You could deal with it using a: Select Case yourToolBarName.Buttons.IndexOf (e.Button) for example.
-
TextBox / RichTextBox - displaying the endHi I'm using a TextBox (or could use a RichTextBox) to display a file. I want it to default to showing the last few lines of the file, rather than the first. I've had a look at MSDN but I can't seem to find anything relevant. Can you help? SH
-
Royal MailBut isn't a bit crap that the recipients don't take the trouble to put them through the right letter box?
-
Setting a form's location and sizePerfect. And by inserting the middle three lines into the Load event, and changing 'newForm' to 'Me', I've managed to change the main form as well. Don't worry about the saving - I've got that bit sorted out. Thanks for your help.
-
Setting a form's location and sizeIs it possible to set a form's location and size before displaying it? I have a couple of resizable forms in my current project. I'd like to have the app remember the size and location of the forms when the user last closed them.