The*_*ner 2 c# select listview winforms
当我从列表视图中单击"项目"时,我需要帮助才能获得响应.知道有selectindexchanged,但当我尝试显示一个MessageBox没有任何反应时,已经尝试了很多其他的东西,但没有设法提出一些东西.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
...
while (reader.Read())
{
string alio = reader["fornamn"].ToString();
string efternamn = reader["efternamn"].ToString();
ListViewItem lvi = new ListViewItem(alio);
listView1.Items.Add(lvi);
lvi.SubItems.Add(efternamn);
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Run Code Online (Sandbox Code Playgroud)
假设81.private void listView1_SelectedIndexChanged已正确链接到listview,您需要查询listview以找出所选内容:
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if(this.listView1.SelectedItems.Count == 0)
return;
string namn = this.listView1.SelectedItems[0].Text;
// Create the sql statement to retrieve details for the user
string sql = string.Format("select * from kunder where fornamn = '{0}', namn);
// do the same as you do to create a reader and update the controls.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21703 次 |
| 最近记录: |