Pour les professionnels de l’informatique > Forums - Accueil > Interoperability Conversations (Archived) > General Discussion I am trying to retrieve a selected value from a listbox and store it in a string variable using Win API
Poser une questionPoser une question
 

Discussion généraleGeneral Discussion I am trying to retrieve a selected value from a listbox and store it in a string variable using Win API

  • vendredi 23 janvier 2009 12:00ChandrashekarYalagi Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    I am trying to retrieve a selected value from a listbox and store it in
    a string  variable.
    I am using the following code:
                int count = 0;
                List<string> retVal = new List<string>();
                string item;
                IntPtr zero = new IntPtr(0);          

                //Get the count of items in the list
                IntPtr ptr = SendMessage(listBox1.Handle, LB_GETCOUNT, zero, zero);
               
                count = ptr.ToInt32();

                StringBuilder sbText = new StringBuilder(256 + 1);
                SendMessage(listBox1.Handle, LB_GETTEXT, (count - 1), sbText);
                string str = sbText.ToString();

                MessageBox.Show("Text:" + str.Trim());
       
     This does not work and when I look at the value of Text it is
        "[09]" and not as I expected.

    im passing the listbox handle to VC dll, which in turn will post back message to listbox.the problem is "listbox.count" shows me zero.so im using WIN API to retrieve the text from listbox. using LB_GETCOUNT im able to get the counts correctly but using LB_GETTEXT it gives me some junk value.

Toutes les réponses