C# listview 的listView1.SelectedItems[0]问题
请高手帮忙指点下此代码第一次选择可以去除istView1.SelectedItems[0].Tag的值``之后再点就报异常高手指点privatevoidlistView1...
请高手帮忙指点下 此代码第一次选择可以去除istView1.SelectedItems[0].Tag的值`` 之后再点就报异常 高手指点
private void listView1_SelectedIndexChanged(object sender,EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
int index = Convert.ToInt32(listView1.SelectedItems[0].Tag);
MessageBox.Show(index.ToString());
//string sql = string.Format("select studentid,loginid,loginpwd from student where studentid={0} ", index);
//SqlDataReader reader = help.Datereader(sql);
//if (reader.Read())
//{
// textBox1.Text = reader["loginid"].ToString();
// textBox2.Text = reader["loginpwd"].ToString();
//}
//reader.Close();
//DBHelper.connection.Close();
} 展开
private void listView1_SelectedIndexChanged(object sender,EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
int index = Convert.ToInt32(listView1.SelectedItems[0].Tag);
MessageBox.Show(index.ToString());
//string sql = string.Format("select studentid,loginid,loginpwd from student where studentid={0} ", index);
//SqlDataReader reader = help.Datereader(sql);
//if (reader.Read())
//{
// textBox1.Text = reader["loginid"].ToString();
// textBox2.Text = reader["loginpwd"].ToString();
//}
//reader.Close();
//DBHelper.connection.Close();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询