ComboBox and TextChanged again (or still)
I see a couple of posts around this topic but oddly, not this exact question, at least not with an answer.
I created two projects, both Windows Application, one in VB 2005, one in C#. I have .NET 2.0 installed.
Each project consists of a form with a single ComboBox, and the DropDownStyle of the ComboBox is DropDown.
I need to be able to catch both changes to the selection in the list or keyboard edits in the box.
In both programs, I add an item to the drop down list when I load the form. Then, I try selecting and then editing. In VB, selecting the item first fires the ComboBox1_TextChanged sub and then the ComboBox1_SelectedIndexChanged sub. Editing fires only the
ComboBox1_TextChanged. This is fine.
In C#, however, selecting the item fires only the ComboBox1_SelectedIndexChanged method, while editing via keyboard fires nothing.
I'd like to continue to use C# here but I can't if this dowsn't work. Why isn't this behavior working in C# when it works fine in VB?
TIA.
Gabriel
In VB, I have:
Public Class Form1
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
...
End Sub
Private Sub ComboBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
...
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("one")
End Sub
End Class
In C#, I have:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("one");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
...
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
...
}
}
}

