Click here to Skip to main content
15,887,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone!

I have an issue with typing in zeros in a combobox that is layed over a datagridview cell. It essentially clears out everything in front of it. This only happens on the first time you enter the cell. If you retype in the same cell while that same cell is active, it lets you type in everything. Has anyone ever heard of this issue before? Can anyone shed some light as to what makes it behave that way? This is only happening when I try to enter a 4-digit year.

My datagridview cell click (relevant) code:
C#
if (dataGridView1.CurrentCell.ColumnIndex == 3)
                    {                        
                        comboBox1.Show();

                        comboBox1.Items.Clear();
                        comboBox1.Text = "";

                        SqlCeCommand year_comm = new SqlCeCommand("SELECT DISTINCT year FROM vehicles ORDER BY year DESC", conn);

                        year_comm.CommandType = CommandType.Text;
                        year_comm.ExecuteNonQuery();

                        SqlCeDataReader year_dr = year_comm.ExecuteReader();

                        while (year_dr.Read())
                        {
                            comboBox1.Items.Add(year_dr["year"]);
                        }
                    }


My combobox text changed code:
C#
private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text != "")
            {
                dataGridView1.CurrentCell.Value = comboBox1.Text;
            }
        }


Any help/pointers will be appreciated.

If I type in "2014" in the first time, I should see 2014.
What I see the first time is after the 0, I don't see the 2 anymore until I retype it.
Posted
Comments
Sergey Alexandrovich Kryukov 17-May-13 10:33am    
The problem might be not in the code you show. If you need anyone to look at it, you should make a very different code sample. One of the ways to do it is to create complete code in one file, without using the designer, all in manually written C# code, which is quite possible.

By the way, if it won't reproduce the problem, it will already give you enough food for thought.

—SA
joshrduncan2012 17-May-13 10:38am    
Thanks SA. I'm trying to satisfy the boss. I know he's gonna look at it and wonder why it's doing that before we present this to the client. I know there is an event that I'm missing that I can't figure out how to prevent that from happening.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900