按下按钮后C#Combo

按下按钮后C#Combo

本文介绍了按下按钮后C#Combo Box变得不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void lists()
        {

            foreach (string s in tracker.projectsCollection)
            {
                comboBox1.Items.Add(s);
            }

            textCase.AutoCompleteCustomSource = tracker.namesCollection;
            textCase.AutoCompleteSource = AutoCompleteSource.CustomSource;
            textCase.AutoCompleteMode = AutoCompleteMode.None;


// I got error when using this combo box's auto suggestion code
            comboBox1.AutoCompleteCustomSource = tracker.projectsCollection;
            comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;


            foreach (string s in tracker.namesCollection)
            {
                if (!listBox1.Items.Contains(s))
                {
                    listBox1.Items.Add(s);
                }
            }

        }

public void get_refresh()
        {
            try
            {
                    Gif_loader_thread();
                    listBox1.Items.Clear();
                    textCase.AutoCompleteCustomSource.Clear();
                    tracker.namesCollection.Clear();
                    tracker.projectsCollection.Clear();
                    comboBox1.Items.Clear();
                    comboBox1.Items.Add("-- Select Project --");
                    tracker.InitialHits();
                    lists();
                    asyncapp();
                    labelResponse.Text = "Refresh successfully";
                    comboBox1.SelectedIndex = 0;

            }
            catch (Exception ex)
            {
                exception_handling(ex);
            }
        }

 public void Gif_loader_thread()
        {
            Thread th = new Thread(new ThreadStart(pictureBox1.Show));
            th.Start();
            timer1.Interval = 3000;
            timer1.Start();
        }

private void btnRefresh_Click(object sender, EventArgs e)
        {
                Gif_loader_thread();
                Thread th = new Thread(get_refresh);
                th.SetApartmentState(ApartmentState.STA);
                th.Start();
                textCase.Focus();
                textCase.SelectAll();
        }

以上是我的代码。

我的组合框中有自动建议属性。我收到错误"当前线程当前线程必须设置为单线程公寓STA模式才能进行调用。"但是当我使用这个代码时;我摆脱了这个错误。但是,当我按下刷新按钮时,现在我的组合
将不可见。

I have auto suggestion property in my combo box. I was getting error "Current thread current thread must be set to single thread apartment STA mode before ole calls can be made.." but when I use this code; I get rid of this error.But, now my combo will invisible when I pressed the refresh button.

th.SetApartmentState(ApartmentState.STA);

如何取回我的组合框?这是我的问题?

How can i get back my combo box? that is my question?

推荐答案

线程一是用于显示进度图像...

Thread One is used to show a Progress image...

线程2用于填充控件。

按钮事件正在调用 Gif_loader_thread()显示进度图像&然后调用
get_refresh()来填充控件,但

Button Event is calling Gif_loader_thread() to show Progress image & then callsget_refresh() to populate controls but

再次调用 Gif_loader_thread()&从而使s creen无反应......

inside it again calls Gif_loader_thread() & thus makes the screen unresponsive...


这篇关于按下按钮后C#Combo Box变得不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:54