IT プロフェッショナルのための技術情報サイト > フォーラム ホーム > 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.

すべての返信