按下按钮后C#Combo Box变得不可见

编程入门 行业动态 更新时间:2024-10-25 07:30:52
本文介绍了按下按钮后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?

推荐答案

两个线程,一个计时器..

Two Threads, One Timer..

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

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 calls get_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变得不可见

本文发布于:2023-11-08 06:55:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按下   按钮   Box   Combo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!