Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

C# Combo Box Auto Suggestion code gives error 'current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it'

$
0
0
 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.Start();
                textCase.Focus();
                textCase.SelectAll();
        }

The above is the code that I am using.

I am getting error "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it." when applying auto suggestion to combo box like this in my lists() function:

comboBox1.AutoCompleteCustomSource = tracker.projectsCollection;
comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

I want auto suggestion of combo box to work perfectly without getting any errors???



Viewing all articles
Browse latest Browse all 1710

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>