Resources for IT Professionals > Página Inicial dos Fóruns > 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
Fazer uma PerguntaFazer uma Pergunta
 

Discussão GeralGeneral Discussion I am trying to retrieve a selected value from a listbox and store it in a string variable using Win API

  • sexta-feira, 23 de janeiro de 2009 12:00ChandrashekarYalagi Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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.

Todas as Respostas