Recent Post

Thursday, March 28, 2013

Combox ajax trong winfrom =)))

by Unknown  |  at  12:17 AM

Sử dụng Combobox như ajax trong winfrom ^^! chém tí thui . ko sử dụng các hàm API thì đây cũng là 1 vidu tốt



//Bắt sự kiện TextChanged của combobox cần làm :

  private void cmbbuucucnhan_TextChanged(object sender, EventArgs e)
                      {            bool isExist;
                ComboBox box = (ComboBox)(sender);
                string txt = box.Text;
                int posCursor = box.SelectionStart;
                if (posCursor != 0)
                { cmbbuucucnhan.DroppedDown = true;
                isExist = true;
               for (int boxIndex = 0; boxIndex < box.Items.Count; boxIndex++)
                {     if (box.Items[boxIndex].ToString() == txt.ToString())
                        {
                        box.Text = (string)(box.Items[boxIndex]);
                        box.SelectionStart = posCursor;                    
                        isExist = true;
                        break;
                        }
               }  if (!isExist)
                    {
                    box.Text = txt.Substring(0, posCursor - 1) + txt.Substring(posCursor + 1 - 1);
                    box.SelectionStart = posCursor - 1;            
                    }
                }              
        }
file cs đính kèm

0 comments:

Proudly Powered by Blogger.