Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView selectedindexchanged

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)
    {

    }
}
like image 284
TheZozoOwner Avatar asked Sep 15 '25 20:09

TheZozoOwner


1 Answers

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.
}
like image 66
Eddie Paz Avatar answered Sep 18 '25 17:09

Eddie Paz