ListView selectedindexchanged
26,937
Assuming that 81.private void listView1_SelectedIndexChanged is properly linked to the listview, you will need to query the listview to find out what's selected:
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.
}
Author by
TheZozoOwner
Working as a Software Developer. Been doing it for more than 5 years. At my current workplace, I have been working with C# and React. I'm learning much about the cloud and how to migrate to it. Everything from CI/CD to Infrastructure as code. Coooooool stuff!
Updated on May 13, 2020Comments
-
TheZozoOwner about 4 years
I need help to get a response when I click on an "Item" from a list view. Know that there is selectedindexchanged, but when I try to display a MessageBox so nothing happens, have tried lots of other things but have not managed to come up with something.
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) { } }