I have a problem that is bifold:
Part 1: I have an MDI parent with numerous mdi children, these are created on startup and only destroyed when the application is shut down. The rest of the time they are just hidden/shown. However, when I hide a form (either by frm.Hide() or frm.Visible = false) and show it at a later time, its position resets. Is this common behavior? Should I hold position manually and set it on a show event? This seems a bit like overkill...
Part2: I have a custom Class that implements a ToString() operator, I use this class as items in a ComboBox, the ToString() operator enters the text nicely in the ComboBox EXCEPT when I add items at runtime, which is exactly what I need. Calling cmb.Refresh() does not refresh the items, the only thing that does the job is if I hide the entire form and then show it again, which is pretty dirty (I dont want to do that every time I add an item to the ComboBox), and brings me back to part1.
Any ideas how to refresh the ComboBox, so that it correctly updates its contents?
Thank you,
Jagg
Loading
JaggPosted Jul 5, 2007, 11:06 AM
JaggPosted Jul 5, 2007, 5:12 AM
Thank you very much for the help, I figured the window would behave as the tooltip stated: The position of a window when it first appears...
As for the ComboBox, it's rather difficult to post my code as it is part of a very big program, where the ComboBox items get created widely spread throughout the program.
I will try to explain to the best of my abilities: I have a class StringWrapper:
public class StringWrapper
{
public Object Tag = null;
public String Text = "";
public StringWrapper(String str)
{
Text = str;
}
public static implicit operator StringWrapper(StringWrapper str)
{
return new StringWrapper(str);
}
public static implicit operator String(StringWrapper strw)
{
return strw.Text;
}
public override String ToString()
{
return Text;
}
}
I add this to a ComboBox like this:
cmb.Items.Add(new StringWrapper("Foo"));
The problem I have is that when I change an item's text at runtime it doesn't update, e.g.:
((StringWrapper)(cmb.Items[0])).Text = "Bla";
In this case cmb will still contain "Foo" in the dropdownlist. When I hide the form, and show it again after, it's updated. But this is not an acceptable way for me. Any pointers?
Jagg
Jan MontanoPosted Jul 5, 2007, 3:13 AM
For Part I: You have to set the StartPosition of your MDI Children form to Manual. By Default it's set to WindowsDefaultLocation. Setting it to Manual will retain the location of your form.
For Part II: Could you show us a bit of code? Normally when I refresh the contents of my combobox, I first call the comboBox1.Items.Clear() method before reloading the contents.
Cheers,
Jan