Having one combobox updating another: what sequence of update is best?

M

murdock

I am having an issue with graphical corruption upon re-selecting a
combobox which upon 'selected index change' event should list file
names in that folder in a separate combobox. Here is the code:

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
IniFile INI = new IniFile(@"c:\\data\TM.ini");

string MisFileDir = INI.IniReadValue("Main", "MisFileDir");

//MessageBox.Show(MisFileDir + @"\" + this.comboBox2.Text +
@"\");

DirectoryInfo dir = new DirectoryInfo(MisFileDir + @"\" +
this.comboBox2.Text + @"\");

FileInfo[] misfiles = dir.GetFiles();

comboBox1.Items.Clear();

comboBox1.BeginUpdate();

foreach (FileInfo f in misfiles)
{
comboBox1.Items.Add(f.Name);
}
comboBox1.Update();
}

As you can see, I'm using an INI file class that utilizes a
kernel32.dll function to read from the INI. (see this article -
http://www.codeproject.com/csharp/cs_ini.asp?df=100&forumid=3467&exp=0&select=359787)

This part works perfectly well. And upon the first selection of
comboBox2 , comboBox1 usually updates fine with a list of files in the
given folder.

The problem comes primarily when I select a different index in
comboBox2, the comboBox1 imagery corrupts. I can still see the indexes,
but the text of that comboBox is invisible or garbled. [yes i should
have used the opposite numbers for their names! sorry for confusion:)]

Question:
My question is, am I updating the comboBox1 items in the appropriate
order? What is the best way to clear a combobox and re-add items to it?

Here is an image of the corruption:
http://seow.trianglesimsociety.org/corruptedimage.JPG

Thanks for any suggestions you may be able to provide.

MurdockSE
 
M

MurdockSE

Oops. Wrong group. I figure I will reply with my own answer to this.

"I was able to fix this drop down graphic corruption by removing the
BeginUpdate and Update calls. So, all I needed to do was Clear, then
Add items to the comboboxes. Thanks anyways.

MurdockSE"
 

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top