I am trying to explain the issue as clearly as I can.
It is comboBoxABC, I wrote below code for the combo box. I can select an item from the dropdown list, or I can enter my own value, such as Hello. If I am in the process of entering string, Cursor shows at the end of string (the one on the left of screenshot).
No matter after I select an item or after finish entering my own value, if I use mouse to click somewhere inside combo box at the moment, the cursor cannot stay where I click, and Cursor jumps to the beginning of string (the one on the right of screenshot), after jumping to the beginning of string (before H, H is the first character of Hello), it flashes for a few times, maybe 5-6 times, then stop flashing. From there, if I want to delete the string Hello, I have to use Delete key, not backspace key, since the Cursor is at the beginning of string.
I use same code (below code) to check textbox value, if I click somewhere inside textbox, the Cursor will not jump to beginning of string, it can stay where I click.
It seems it only happens to combo box, why? How to fix it?
Thanks.
private void comboBoxABC_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;
if (!char.IsLetter(ch) && ch != 8)
{
e.Handled = true;
MessageBox.Show("Only letter is allowed.");
}
}
Edit: Due to 1000 character limit on comment, I added code to this original post. After removing comboBoxABC_KeyPress , the problem remains, so probably it is comboBoxCountry_Click (it is same combo box as comboBoxABC in this question, I use different name on different posts) causing the problem, only two events are associated with this comboBox. The code is also in another post ( c-error-too-few-parameters-combo-box-based-on-data.html ), as mentioned in below comment.
private void comboBoxCountry_Click(object sender, EventArgs e)
{
comboBoxCountry.Items.Clear();
OdbcConnection Cn = new OdbcConnection(GlobalVariables.DatabaseConnectionString);
Cn.Open();
string qCountry = "SELECT DISTINCT Country from Place";
using (var cmd = new OdbcCommand(qCountry, Cn))
{
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
string sColString = reader.GetString(0);
comboBoxCountry.Items.Add(sColString);
}
}
}
Cn.Close();
}