Case sensitivity issue while loading the Data into Combobox

deepu chandran
deepu chandran used Ask the Experts™
on
Hi Experts,

 I am facing a problm based while setting values to a Combo box. In my program i am using two combo box and One flexgrid. The Combobox are having data like A to Z and a To z. I will add the data into the Flex grid and Delete the Data From it. While Deleting the Data from the Flex grid if the data is Small letters, it will auto matically chage to Capital letters.

Eg, the Flexgrid data is a and b, while select the paticular row and press Remove button, it will reassign the data. But it is loading as A and B. Both the combobox is having Member variables

Thank you in advance
Deepu
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AndyAinscowFreelance programmer / Consultant

Commented:
Post your code

Author

Commented:
hi,

/*m_cbsSrcPinName(Source Combo) is getting Data From Flex Grid*/
m_cbsSrcPinName = m_ctlPindetFlex.GetTextMatrix(m_ctlPindetFlex.GetRowSel(),1);
/*m_cbsDesPinName(Dest Combo) is getting Data From Flex Grid*/
m_cbsDesPinName = m_ctlPindetFlex.GetTextMatrix(m_ctlPindetFlex.GetRowSel(),3);
..... (Other Calculations are here)
UpdateData(false);  
This is just a code segment
m_cbsSrcPinName : Member variable for First Combo
m_cbsDesPinName : Member Variable for Second Combo
Both are CString
Deepu
>>>> I will add the data into the Flex grid and Delete the Data From it.
That is not clear. Why do you add *and* delete? Do you mean you want to *update* the cells by first *deleting* the old contents and *adding* the new contents after?  If so, I would assume you get the new data wrongly from the A_Z combobox and not from a-z combobox (though I haven't understand why you need these at all).

>>>> Both the combobox is having Member variables
check the definitions in the DoDataExchange function. Maybe you mixed up both comboboxes when creating the members with the wizard.

Regards, Alex
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Author

Commented:
Hi Alex,

Actually what i am doing is, having  two comboboxes. Both are having Pin numbers. Take one as Source and Another as Destination. I will add the Source <-> Deatination into the Link. While adding, i need to edit some of the lines from the Grid. For that i will load the Data from the Grid back to the Combo.

I think this will clear my question

Deepu
AndyAinscowFreelance programmer / Consultant

Commented:
Use a breakpoint and check the text you get from the flex grid.  That is to make certain the small->capital conversion is there and not elsewhere in your code.
>>>> m_cbsSrcPinName = ...
It seems you want to 'select' data in the combobox(es) rather than adding to the flexgrid as you stated in your question?

>>>> UpdateData(false);  
That statement put data from members to screen. In case of combobox strings it fillss the edit box of a combobox.

Do you mean by doing that the data in the flexgrid changes from lower case to upper case? Did you add the flexgrid to the DoDataExchange somehow?

Regards, Alex

Author

Commented:
Hi AndyAinscow,
I put beakpoint and Checked the value getting from the Fl;ex Grid is currect. This is working for numarals correctly. That means the pin numbers might be numbers, some times alphabets. If the Pin numbers are only Small letters then no problem.The Problem will come only when the combo is having both small and Capital Letters.

Hi Alex,

I got problem While getting the Data from the Flex grid. If i dont give UpdateData(false) then it is not loading the value correctly. The Flex Grid also included in nthe DoDataExchage()

Thank you for Faster commends
Deepu
AndyAinscowFreelance programmer / Consultant

Commented:
There are combobox settings - uppercase and lowercase.  Do you have one of those set to true?  (which would force only upper or lower case in that combo)

Author

Commented:
Hi,
I tested that also  but it is converting my Upper case also to Lower case.  That means i want both Upper cas e and Lower case charactors.

Thank you
Deepu
AndyAinscowFreelance programmer / Consultant

Commented:
For both upper AND lower case then both need to be false.  
You keep talking about your lower case being converted to uppercase somewhere.

Author

Commented:
Hi,
We cannot be Able to Select both options. I checked that in the Properties of the Combo box
Deepu.
AndyAinscowFreelance programmer / Consultant

Commented:
To repeat myself
For both upper AND lower case then both need to be false.  

Author

Commented:
Hi,
That Options are False
Deepu
AndyAinscowFreelance programmer / Consultant

Commented:
Please post your code.

/*m_cbsSrcPinName(Source Combo) is getting Data From Flex Grid*/
m_cbsSrcPinName = m_ctlPindetFlex.GetTextMatrix(m_ctlPindetFlex.GetRowSel(),1);
/*m_cbsDesPinName(Dest Combo) is getting Data From Flex Grid*/
m_cbsDesPinName = m_ctlPindetFlex.GetTextMatrix(m_ctlPindetFlex.GetRowSel(),3);
..... (Other Calculations are here)    <<<---------------------------------- WHAT HAPPENS HERE
UpdateData(false);  

Author

Commented:
Hi AndyAinscow,

I simulate the Problem with the small Dialog base application,

i put a Combobox, and Hardcode the Data as A,B,C,D,a,b,c and d. Changed the Type as Drop List.
Then i put one Text box to get and Load the Data.
Following are the Code
void CTest_ComboDlg::OnAddData()
{
      UpdateData(true);
      m_txtPinDetail = m_ctlVal;      //Get Data to the Text Box
      UpdateData(false);
}

void CTest_ComboDlg::OnAdd()
{
      UpdateData(true);
      m_ctlVal = m_txtPinDetail;  // assign the Text box value to the Combobox
      UpdateData(false);
}
Please Check it out
Deepu

Ok, I could reproduce the problem: it goes wrong if you select a uppercase letter in the combobox and move it to the editbox. After that the editbox correctly has an uppercase *but* the combobox has a lowercase *selection*. The problem is the DoDataExchange which calls a
   ::SendMessage(hWndCtrl, CB_SELECTSTRING, (WPARAM)-1,
                             (LPARAM)(LPCTSTR)value)  
what means it doesn't write the given string into the editbox of the combobox but makes a selection. Unfortunately, a selection is not case-sensitive and selects the lowercase string instead of the uppercase one.

I will find out what you can make as a workaround.

Regards, Alex
In DoDataExchange you'll find a statement like

    DDX_CBString(pDX, IDC_COMBO1, m_cbsCombo1);

Replace it by the following code:

    if (pDX->m_bSaveAndValidate)
         DDX_CBString(pDX, IDC_COMBO1, m_cbsCombo1);
    else
        GetDlgItem(IDC_COMBO1)->SetWindowText(m_cbsCombo1);

and it will work. By that I replaced the CB_SELECTSTRING message by WM_SETWINDOWTEXT what writes to the edit part of the combobox rather than selecting from the drop list.

Regards, Alex
 

Note, you can have a different  behavior regarding upper and lowercase when you checked the sort option, or when you have a different order than me (I have a b c d A B C D).  The point is that the UpdateData(false) *selects* the first occurrence of the string regardless if it is lowercase or uppercase. So it always goes wrong if you select the entry with a higher index.

Regards, Alex
AndyAinscowFreelance programmer / Consultant

Commented:
Assuming the comment by Alex is what is happening (having X and x as choices in the combo and no matter if I have X or x it always selects X) then why didn't you ask that question?
Why ask about 'why is my variable being converted into uppercase?' - that isn't what was happening.
>>>> and no matter if I have X or x it always selects X
Maybe it wasn't so easy to recognize... It only happens because of the UpdateData(FALSE) which wasn't done when the value in the combobox was selected but when it was moved to the edit field (or flexgrid in the original form). And it looks like as if the update of the edit field (or flexgrid) would convert the contents of the combobox (which was correct before). So, indeed it was strange.

        edit [   ]
        combo [   ]  
                    |   A   |
                    |   B   |
                    |   a    |          

select a in drop list:

        edit [   ]
        combo [ a ]  

press button "combo to edit"

       edit [ a ]
       combo [ A ]

BTW, in my test I had sorted it differently. So, my conversion was from upper to lower char.

Regards, Alex
The docs to CB_SELECTSTRING say:

 ... The search is not case sensitive, so this string can contain any combination of uppercase and lowercase letters ...

Bingo.

Regards, Alex
AndyAinscowFreelance programmer / Consultant

Commented:
>>>> and no matter if I have X or x it always selects X
Maybe it wasn't so easy to recognize...
True, but the description of the problem seemed to be two combobox's, enter something in the grid in small letters, hit a button and the result appears in the combo but now in capitals.




There seems to be these two main types of people:

There is a problem, I must identify the problem, now I will solve the problem.
and
There is a problem, I must do something, this is something, therefore I must do this.


Occasionally one does come across a third type
There is a problem, if I ignore it then it will go away.

Author

Commented:
Hi Experts,

Thank you for your valueable commends, i solved the problem. The problem was very simple. If we use the member variable as CString, then the values will be Case insensitive. Instead of that i used int as the member variable.

Thank you
Deepu
AndyAinscowFreelance programmer / Consultant

Commented:
<Instead of that i used int as the member variable.>

?? a isn't an int, nor is A

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial