ComboBox控件绑定了表Customer的一个字段address,
另一个控件DataGrid绑定了Customer表(全部字段)。
当点击DataGrid的某行后,ComboBox中出现了对应的address,
这时测试address所对应的ComboBox.SelectedIndex还是为0,为什么?
如何知道其实际对应的ComboBox.SelectedIndex?
呵呵,是不是很傻^_^!
ComboBox绑定后不会向LZ说的SelectedIndex为0
以下代码是在2005测试通过
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlClient.SqlConnection
Dim strConn As String = "data source=127.0.0.1;initial catalog=hhdata;user id=sa;password=12345678;"
conn = New SqlClient.SqlConnection(strConn)
conn.Open()
Dim aa As New DataSet
Dim daaa As New SqlClient.SqlDataAdapter
Dim sqltile As String = "select s_username from s_user"
daaa.SelectCommand = New SqlClient.SqlCommand(sqltile, conn)
daaa.Fill(aa)
DataGridView1.DataSource = aa.Tables(0)
ComboBox1.DataSource = aa.Tables(0)
ComboBox1.DisplayMember = "s_username"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ComboBox1.SelectedIndex
End Sub
当点击Button1的时侯,DataGridView1在第几行,ComboBox1.SelectedIndex的值就显示数字几,不会全部显示是0