none
How to change selected index of combobox using Win API?

    Question

  • Hello,

    How to change selected index of combobox on one external exe using Win API?
    That combobox style is dropdownlist.

    I tried to use
    SendMessage(GetDlgItem(hWnd, 301), CB_SETCURSEL, 2, 0)
    where hWnd=hWnd of exe
             301=control id of combobox

    But it doesnt change the selected index, itonly changes the text portion of the combobox.

    Even I tried to use
    SendMessage(GetDlgItem(hWnd, 301), CB_SELECTSTRING, -1, "bar"), but it doesnt work..!

    Please suggest a solution..!

    Regards,
    Raj

     

    Monday, October 03, 2005 6:09 AM

Answers

  • Hello,

    My problem is I need to set text to the combobox of type CBS_DROPDOWNLIST on one external exe through my vb.net console app and also I want that combobox click event get fired.

    Somehow I managed to get the solution by using the following code.  But Iam not sure the unneccesary/efficiency of this code. 

    I simulate the keypress in the combobox of type CBS_DROPDOWNLIST using Win API functions.

    The code follows...

    1 SendMessage(GetDlgItem(hWnd, 301), WM_SETFOCUS, 0, 0)
    2 SendMessage(GetDlgItem(hWnd, 301), WM_CHAR, 66, WM_KEYDOWN)
    3 SendMessage(GetDlgItem(hWnd, 301), WM_CHAR, VK_RETURN, WM_KEYDOWN)
    4 SendMessage(GetDlgItem(hWnd, 301), WM_KILLFOCUS, 0, 0)

    Where  hWnd=hWnd of the exe
              301 = control id of combobox
              66 = Key code for B

    Here I want to select the item which starts with B(there is only one item which starts with letter B) inside the combobox.  If there are many items which starts with B, I repeat the line(numbered 2 in the above code) until I get that item inside combobox.

    Any suggestions are welcome.....

    Raj

    Tuesday, October 04, 2005 3:59 AM

All replies

  • Hello,

    Sorry, I reframe my question

    I am able to change the current selected index of a combobox(type:dropdownlist) using

    SendMessage(GetDlgItem(hWnd, 301), API.CB_SETCURSEL, 2, 0)
    where hWnd: hWnd of exe
          301 : control id of the combobox on that exe
          2   : index to be set 

    but the click event of that combobox doesnt fire.

    I want the combobox click event to get fired when I change the index of that combobox.
    How do I do?

    Regards
    Raj

     

    Monday, October 03, 2005 9:19 AM
  • Hello,

    My problem is I need to set text to the combobox of type CBS_DROPDOWNLIST on one external exe through my vb.net console app and also I want that combobox click event get fired.

    Somehow I managed to get the solution by using the following code.  But Iam not sure the unneccesary/efficiency of this code. 

    I simulate the keypress in the combobox of type CBS_DROPDOWNLIST using Win API functions.

    The code follows...

    1 SendMessage(GetDlgItem(hWnd, 301), WM_SETFOCUS, 0, 0)
    2 SendMessage(GetDlgItem(hWnd, 301), WM_CHAR, 66, WM_KEYDOWN)
    3 SendMessage(GetDlgItem(hWnd, 301), WM_CHAR, VK_RETURN, WM_KEYDOWN)
    4 SendMessage(GetDlgItem(hWnd, 301), WM_KILLFOCUS, 0, 0)

    Where  hWnd=hWnd of the exe
              301 = control id of combobox
              66 = Key code for B

    Here I want to select the item which starts with B(there is only one item which starts with letter B) inside the combobox.  If there are many items which starts with B, I repeat the line(numbered 2 in the above code) until I get that item inside combobox.

    Any suggestions are welcome.....

    Raj

    Tuesday, October 04, 2005 3:59 AM