2

I have a Combobox in my WPF, where the user can write a text to be searched in English, Japanese or Korean.

I don't have any problems with Japanese or English, but the Korean characters are not being recognized by the control, but only if they are written directly in the Combobox. They are correctly recognized if I copy/paste the Korean text.

For example, I have this test code:

private void mTextKey_KeyUp(object sender, KeyEventArgs e)
{
   if (mTextToSearch.Text != null)
     {
       string test = mSearchKey.Text;
       MessageBox.Show("Text in box: " + test);
     }
}

If I write "a" in the Combobox, I get this message: "Text in box: a" (correct) If I write the Korean character "ㅐ", I get this message: "Text in box: " (incorrect) If I copy/paste the Korean character "ㅐ", I get this message: "Text in box: ㅐ" (incorrect)

I have absolutely no idea why I only have problems if I write directly in the Combobox, but not when pasting the text.

Does anybody know why this happens in Korean? Thanks!

Ignacio
  • 21
  • 1
  • I can't see exact code so it's just a guess: many Korean characters (besides CJK) doesn't fit one single UTF-16 encoded character. It means that `" ㅐ".Length == 2` (2 UTF-16 code points then 4 bytes). However `KeyUp` event is fired for each code point (you should check, sorry I don't know IME for Korean). According to where/what you do with such input then `KeyUp` event isn't best place to put such logic (unless you want to handle that properly but UTF-16 isn't synchronized then it's not so easy). I'd try to **move that code in `TextChanged` event.** – Adriano Repetti May 14 '14 at 13:35
  • Thank you for this perspective! I didn't consider it. I readjusted the code and I could make it work. Thanks again! – Ignacio May 15 '14 at 09:30

0 Answers0