Combo box - set to display the nth string
-
I have a combo box that I create on a dialog window by adding strings to it from a file. Once a selection is made the box shows that selection as long as I keep the window open. But after I close it and return the box is blank until it is selected again. Is there anyway to init this to display a certain item? I have the index that I wand to set it too.. Thanks for any help
-
I have a combo box that I create on a dialog window by adding strings to it from a file. Once a selection is made the box shows that selection as long as I keep the window open. But after I close it and return the box is blank until it is selected again. Is there anyway to init this to display a certain item? I have the index that I wand to set it too.. Thanks for any help
From MSDN : CComboBox::SetCurSel int SetCurSel( int nSelect ); Remarks Selects a string in the list box of a combo box. If necessary, the list box scrolls the string into view (if the list box is visible). The text in the edit control of the combo box is changed to reflect the new selection. Any previous selection in the list box is removed. ~RaGE();
-
I have a combo box that I create on a dialog window by adding strings to it from a file. Once a selection is made the box shows that selection as long as I keep the window open. But after I close it and return the box is blank until it is selected again. Is there anyway to init this to display a certain item? I have the index that I wand to set it too.. Thanks for any help
Check out CComboBox::SetCurSel / CB_SETCURSEL. You have to be careful if the combobox is sorted, but CB_ADDSTRING gives you the "post sorting" number. Iain.
-
Check out CComboBox::SetCurSel / CB_SETCURSEL. You have to be careful if the combobox is sorted, but CB_ADDSTRING gives you the "post sorting" number. Iain.
when using addstring, is there a way to haVE it not ssort the list? im trying to get the word 'none' to come up as default, but another choice in the listbof is 'channel1' so it comes up default. if it wasnt sorted, it would take the first string i put in and use that one. :(
-
when using addstring, is there a way to haVE it not ssort the list? im trying to get the word 'none' to come up as default, but another choice in the listbof is 'channel1' so it comes up default. if it wasnt sorted, it would take the first string i put in and use that one. :(
Just remove the LBS_SORT style. In the resource editor, select the combo box. Bring up its property box. On the 2nd or third tab there is a check box for "sort". Clear the check. Compile. Enjoy! Iain.
-
Just remove the LBS_SORT style. In the resource editor, select the combo box. Bring up its property box. On the 2nd or third tab there is a check box for "sort". Clear the check. Compile. Enjoy! Iain.
ok that works great. now, if anyone sees this, is there a way to get a number returned by SetCurSel()? i need to output which value in my listbox is selected. setcursel(0) forces the first string to be selected. so, if the user changes the selected variable, a number has to be stored somewhere because the program remembers it. so....where is that number at? *.*
-
ok that works great. now, if anyone sees this, is there a way to get a number returned by SetCurSel()? i need to output which value in my listbox is selected. setcursel(0) forces the first string to be selected. so, if the user changes the selected variable, a number has to be stored somewhere because the program remembers it. so....where is that number at? *.*
This is pretty basic stuff... You should find all this information in the MSDN libraries, or any half-decent MFC/Win32 book. Anyway, as I'm in a nice mood... ;) Lookup: CComboBox::GetCurSel (). DDX_CBIndex (...). Just about any example in the Combo Box section here on CodeProject. Iain.