We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Get Selected Item in single listview selection

Hi, 
How to get the selected value from a listview?
My code:

private void sfListView1_DoubleClick(object sender, EventArgs e)
        {


            //Texto da seleção
            string Seleção = sfListView1.SelectedItems[0].ToString();
            //Pego o número do pedido
            /*string Pedido = Seleção.Substring(0, Seleção.IndexOf("-"));
            string Cliente = Seleção.Substring(Seleção.IndexOf("-"), Seleção.IndexOf("-"));
            */
            MessageBox.Show(Seleção);


        }


The code returns the name of the collection and not the selected item



3 Replies

JP Jagadeesan Pichaimuthu Syncfusion Team July 19, 2019 05:29 AM

Hi Matheus, 
 
Thanks for using Syncfusion product. 
 
We have checked the reported issue in our end and we found you directly show the selected item in message. Instead that you can cast the selected item to particular type of data which you bind with control as like the below code snippet. Here we populated the datasource with the collection of USState type, so we can cast the SelectedItem to particular type. 
 
void sfListView1_DoubleClick(object sender, EventArgs e) 
{ 
    //Texto da seleção 
    string Seleção = (sfListView1.SelectedItems[0] as USState).LongName.ToString(); 
    
    MessageBox.Show(Seleção); 
} 
 
We have prepared the simple sample to achieve your requirement. 
 
 
Please refer the below screen shot for your reference. 
 
 
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan 



MA Matheus July 20, 2019 07:53 AM

This work! Thanks!


JP Jagadeesan Pichaimuthu Syncfusion Team July 22, 2019 01:39 AM

Hi Matheus, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Jagadeesan 


Loader.
Live Chat Icon For mobile
Up arrow icon