Resources for IT Professionals > 포럼 홈 > 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
질문하기질문하기
 

일반 토론General Discussion I am trying to retrieve a selected value from a listbox and store it in a string variable using Win API

  • 2009년 1월 23일 금요일 오후 12:00ChandrashekarYalagi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.

모든 응답