Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a dynamic UI in which a combobox(dropdown) is geting created.
how to check if an item is selected from a comboBox.
Any Help
Thanks in advance
Posted
Updated 16-Aug-12 19:16pm
v2

SQL
if comboBox1.SelectedItem != null)
                { //Do Somthing}



Mark if ans is accurate to your question.
 
Share this answer
 
See here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb775792(v=vs.85).aspx

You need the Combobox_GetCurSel macro, perhaps Combobox_GetTextLen & Combobox_GetText too.
 
Share this answer
 
Comments
Midhun PB 17-Aug-12 2:17am    
Thanksfor the reply..
My problem is since it is a dynamic UI,and combobox is not defined. the values are added as -
LoadString(Class::LoadLib,IDS_XXX,String,100);
where where LoadLib is a static HMODULE.
I have tried string.IsNullOrEmpty options.but not working
enhzflep 17-Aug-12 2:57am    
Doesnt matter, just use GetDlgItem(parentsHwnd, combo_id) to get its window.
You must have some way of identifying it at runtime - use that as a means to get its Hwnd.

Is this really plain C/C++? Your latest response tends to indicate otherwise. Please re-tag question if appropriate - I.e wpf, cli.
If you created the combobox dynamically then you have the HWND of the combobox child window (that is the return value of CreateWindowEx) so you dont have to issue GetDlgItem() to get its HWND! You communicate with the combobox by sending messages to that HWND!

Here is a set of combobox related messages:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775845%28v=vs.85%29.aspx[^]

You have to send CB_GETCURSEL message to the HWND of your combobox to find out if an item is selected:
C++
int selected_index = (int)SendMessage(hwnd_combo, CB_GETCURSEL, 0, 0);
if (selected_index == CB_ERR)
{
    // there is no item selected
}
 
Share this answer
 
Comments
pasztorpisti 20-Aug-12 7:57am    
Just a side note: Even if you create the child window dynamically with CreateWindowEx(), you can specify a control id for it by passing in the control identifier to the HMENU parameter of CreateWindowEx() (see the msdn doc). By doing this you should be able to call GetDlgItem() on the HWND of the parent of this control with the control identifier to get the HWND of this control.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900