I have a comboBox that I need to fill using data from Access database.

For this, I get a DataTable with resultset from database, transform this resultset in a List<T> to sort by number and fill the Rows with this List.

The problem is, after selected some value, I can't do any other operation, like click in save button.

Any idea?

Thanks! :)

Recommended Answers

All 2 Replies

Without some code we can not know what is happening.
What do you do when a value is selected?

Here is the method I use to fill the ComboBox:

public static void CriaDataSourceCombo(ref ComboBox combo, DataTable table, DataSet fontedados , string tipo, string tag)
        {
            if (tipo == "texto")
            {
                DataView tabela = new DataView(table);
                tabela.ApplyDefaultSort = true;
                combo.DataSource = tabela;
                combo.ValueMember = OutrosCadastroID();
                combo.DisplayMember = OutrosCadastroDescricao();
            }
            else if (tipo == "numero")
            {
                if (fontedados.Tables.Contains(tag))
                {
                    // Pega os registros da tabela correspondentes aquele Controle
                    table = fontedados.Tables[tag].Copy();
                    // contador, iremos percorrer todas as linhas
                    int i = 0;
                    List<Int32> lista = new List<Int32>();
                    foreach (DataRow linha in table.Rows)
                    {
                        // Registros referentes apenas a coluna descrição da tabela outros cadastros
                        string registro = (table.Rows[i][0]).ToString();

                        // se a string for selecione, não adicionaremos a nossa lista
                        int descricao = 0;
                        try
                        {
                            descricao = int.Parse(registro);
                            lista.Add(descricao);
                        }
                        catch (FormatException fe)
                        {
                            // Caso seja Selecione, adicionamos aos items do combobox
                            if(!(combo.Items.Contains(API.AuxClass.StringSelecione()))){
                            combo.Items.Add(API.AuxClass.StringSelecione());
                            }
                        }
                        i++;
                    }
                    // Organizamos a nossa númericamente
                    lista.Sort(delegate(Int32 item1, Int32 item2)
                    {
                        return item1.CompareTo(item2);
                    });

                    // Percorremos a lista para adicionar os elementos ao ComboBox
                    foreach (Int32 item_lista in lista)
                    {
                        combo.Items.Add(item_lista);
                    }
                    combo.ValueMember = API.AuxClass.OutrosCadastroID();
                    combo.SelectedIndex = 0;
                }
            }
        }

After perform this procedure, the entire form is blocked! I can't do anything, like click in save button, select values at another ComboBox, anything!

Sorry about the portuguese in the code, I'm brazilian!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.