Windows Develop Bookmark and Share   
 index > Windows Forms General > MdiWindowListItem oes not reflect changed form text
• Windows Forms General
• Windows Forms Designer
• ClickOnce and Setup & Deployment Projects
• Windows Forms Data Controls and Databinding
• Windows Forms Sample Applications

MdiWindowListItem oes not reflect changed form text

Just started using the MdiWindowListItem property, but the list does not refesh the text when the text property of the forms changes, until the focus leaves the changed form.

Is there a simple solution to this?

Thanks

abrewerton  Monday, May 01, 2006 7:23 PM

The Window list is refreshed when either the Visible or Active property of the child form is changed.

Toggling the child visibility works, but has an (assumed) undesired visual effect.

However, changing the Active state appears to work well for this. One change handles it.

In the wizard-generated code for your MDIParent class, add the following event handler:

private void ShowNewForm(...) {
// ...
childForm.TextChanged += new EventHandler(childForm_TextChanged);
}

Then add the method that'll kick the activate state when the text changes:
void childForm_TextChanged(object sender, EventArgs e) {
this.ActivateMdiChild( null );
}

John Arlen  Tuesday, May 02, 2006 12:23 AM

The original solution will work with one change:

Add an additional line to the TextChanged handler. This will force the activation to occur at all times:

void childForm_TextChanged(object sender, EventArgs e) {
this.ActivateMdiChild( null );
this.ActivateMdiChild( sender as Form );
}

John Arlen  Thursday, May 25, 2006 6:30 PM

The Window list is refreshed when either the Visible or Active property of the child form is changed.

Toggling the child visibility works, but has an (assumed) undesired visual effect.

However, changing the Active state appears to work well for this. One change handles it.

In the wizard-generated code for your MDIParent class, add the following event handler:

private void ShowNewForm(...) {
// ...
childForm.TextChanged += new EventHandler(childForm_TextChanged);
}

Then add the method that'll kick the activate state when the text changes:
void childForm_TextChanged(object sender, EventArgs e) {
this.ActivateMdiChild( null );
}

John Arlen  Tuesday, May 02, 2006 12:23 AM

I'm having the same issue. Your code worked the first time it changes but after that it does not work and I can't figure out how to make it work properly.

Basically I have one form which I reuse, when the user clicks on a menu item the forms Text property is changed and some data in a grid changes as well. So if I click on one menu item it launches the form and the "Window" menu works, click on the next menu item, it updates the Window menu, do it again and nothing.

Any hel pis appreciated.

Thanks.

duncan.mcleod  Thursday, May 25, 2006 4:34 AM

I have exactly the same problem - child form text changes dynamically as properties of the contained object (e.g. name, saved, etc, change).

Has anyone got a working solution to this - I have tried the above and it does not work after the first change. I've tried various other options too, but no joy so far.

Chris Keeble  Thursday, May 25, 2006 11:28 AM
Glad to see I am not alone on this one. That is exactly my issue.
duncan.mcleod  Thursday, May 25, 2006 3:30 PM

The original solution will work with one change:

Add an additional line to the TextChanged handler. This will force the activation to occur at all times:

void childForm_TextChanged(object sender, EventArgs e) {
this.ActivateMdiChild( null );
this.ActivateMdiChild( sender as Form );
}

John Arlen  Thursday, May 25, 2006 6:30 PM

This certainly forces the update, thanks. However, it's very slow when the form text is bound to a business object's property that changes OnPropertyChanged (e.g. a Name field on the form in question)

I did also have a problem others may want to be careful of - my databound form (databound to a business object) the childForm_TextChanged method is called once when the first character change is made to the name field (on which the form's text is partly based). It is called 3 times when the second change is made, and then 9 times, and then 27 times..... ?! (I am only changing one character at a time).

The Form text is bound with "Never update" and is bound to a read only property on the same object which computes and returns the form text to be displayed....

I fixed this after finding that the event handler was being added (in the MdiChildActivated event handler) ... every time.

I'm guessing this is also where I can resolve the performance issue described at the beginning of this reply (as my fix was to first remove the handler before adding it again)....

 

Chris Keeble  Thursday, May 25, 2006 11:13 PM

I now have a solution that is working perfectly for me - and is straightforward. Please do comment if you think there is a better way (assumes the MDI form's MDIWindowListItem is a ToolStripMenuItem called WindowsMenu).

Private Sub WindowsMenu_DropDownOpening(ByVal sender As Object, ByVal e As System.EventArgs) Handles WindowsMenu.DropDownOpening

Me.UpdateOpenWindowsList()

End Sub

Private Sub UpdateOpenWindowsList()

Static _currentActiveMdiChildFormText As String = String.Empty

If (Not Me.ActiveMdiChild Is Nothing) AndAlso _
_currentActiveMdiChildFormText <> Me.ActiveMdiChild.Text Then

Dim _activeMdiChild As Form = Me.ActiveMdiChild
Me.ActivateMdiChild(Nothing
)
Me
.ActivateMdiChild(_activeMdiChild)
_currentActiveMdiChildFormText = _activeMdiChild.Text

End If

End Sub

Chris Keeble  Friday, May 26, 2006 8:33 AM
For any c# coders this seems to be working for me....

private void toolStripMenuItemWindow_DropDownOpening(object sender, EventArgs e)
{
if (this.ActiveMdiChild != null)
{
Form activeChild = this.ActiveMdiChild;

ActivateMdiChild(null);
ActivateMdiChild(activeChild);
}
}
fs_07801  Wednesday, April 18, 2007 3:10 PM

Used the VB.net code from SmellyMutantCat.

Thanks for this. I know this post was from acouple years ago, but it saved me the time to figure it out myself. Cut and pasted it right in and worked with no modifications.

Thanks again.

E Ranall North  Tuesday, August 12, 2008 7:53 PM

Me too.

Thanks SmellyMutantCat

Powerful Pierre  Friday, October 10, 2008 11:17 AM

You can use google to search for other answers

 

More Threads

• PropertyGrid does not show controlName at Runtime ?
• How to change the color or format of the text displayed on Label control?
• Problem with the SoundPlayer control
• Windows service
• keeping focus on the main window
• tooltips problem: listview tooltips are hidden behind topmost form
• Changing Font in DataGridView - problem
• DateTime Picker-Error
• keys status
• Error Creating Window Handle