Regarding updating one comboBox from another: what order is best for clearing and updating the secon


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=...)

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
 
Ad

Advertisements

M

MurdockSE

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top