天天看點

支援拼音檢索的TextBox擴充控件-使用

我的上一個支援拼音檢索的textbox擴充控件,由于有些網友留言和發郵件問如何用,

如:菜鳥aaa等當時想到肯定大家都會用,就沒上傳示例程式。

原文為:http://www.cnblogs.com/whitewolf/archive/2009/12/03/1615975.html#1717373

既然有人問,那就上傳下是下程式。肯定很多人都知道如何用,請越過就是,不要發弁言。

主要隻有三個屬性暴露出來:

1:maxitemcout:這是在多個下拉條時,顯示多少條可見;

2:searchmode:檢索方式:隻提供了searchmode.contains 和searchmode.startwith包含和以其開始差別;

3:spellsearchsource:檢索的資料源,僅顯現的中文等字元;

主要在它上:有幾種方式設計:

1:設計時:

支援拼音檢索的TextBox擴充控件-使用
支援拼音檢索的TextBox擴充控件-使用
支援拼音檢索的TextBox擴充控件-使用

代碼

2:代碼中;

一般的:

//一般的code為;

            spellsearchboxex1.spellsearchsource = new string[] { "中國", "中國fgdfs", "中阿收費的肌膚", "男生", "女生" };

3:資料庫情況下,本執行個體用的是随機生成中文模拟資料庫情況;

public partial class form1 : form

    {

        public form1()

        {

            initializecomponent();

        }

        private void form1_load(object sender, eventargs e)

            //一般的code為;

            // 連接配接資料庫情況下僅此;

            spellsearchboxexbysql.spellsearchsource = getspellboxsource(getdatatable());

        public string[] getspellboxsource(datatable dt)

            list<string> list = new list<string>();

            foreach (datarow dr in dt.rows)

            {

                if (!convert.isdbnull(dr["text"]))

                    list.add(dr["text"].tostring());

            }

            return list.toarray();

        public datatable getdatatable()

            //這裡是自己的代碼連接配接資料庫僅得到要填的列;

            //本方法沒連資料庫,用随機生成中文模拟獲得datattable

            // datatable dt = db.getdatatable("sql");

            datatable dt = new datatable();

            dt.columns.add(new datacolumn("text", typeof(string)));

            random rn = new random();

            for (int i = 0; i < 50; i++)

                string str ="中" +getrandomchinese(rn.next(8));

                datarow dr = dt.newrow();

                dr["text"] = str;

                dt.rows.add(dr);

            return dt;

        #region 以下隻是随機生成中文,與本控件使用無關;

        public string getrandomchinese(int strlength)

            encoding gb = encoding.getencoding("gb2312");

            object[] bytes = this.createregioncode(strlength);

            stringbuilder sb = new stringbuilder();

            for (int i = 0; i < strlength; i++)

                string temp = gb.getstring((byte[])convert.changetype(bytes[i], typeof(byte[])));

                sb.append(temp);

            return sb.tostring();

        private object[] createregioncode(int strlength)

            //定義一個字元串數組儲存漢字編碼的組成元素 

            string[] rbase = new string[16] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };

            random rnd = new random();

            object[] bytes = new object[strlength];

                int r1 = rnd.next(11, 14);

                string str_r1 = rbase[r1].trim();

                rnd = new random(r1 * unchecked((int)datetime.now.ticks) + i);

                int r2;

                if (r1 == 13)

                {

                    r2 = rnd.next(0, 7);

                }

                else

                    r2 = rnd.next(0, 16);

                string str_r2 = rbase[r2].trim();

                rnd = new random(r2 * unchecked((int)datetime.now.ticks) + i);

                int r3 = rnd.next(10, 16);

                string str_r3 = rbase[r3].trim();

                rnd = new random(r3 * unchecked((int)datetime.now.ticks) + i);

                int r4;

                if (r3 == 10)

                    r4 = rnd.next(1, 16);

                else if (r3 == 15)

                    r4 = rnd.next(0, 15);

                    r4 = rnd.next(0, 16);

                string str_r4 = rbase[r4].trim();

                byte byte1 = convert.tobyte(str_r1 + str_r2, 16);

                byte byte2 = convert.tobyte(str_r3 + str_r4, 16);

                byte[] str_r = new byte[] { byte1, byte2 };

                bytes.setvalue(str_r, i);

            return bytes;

        #endregion

}

支援拼音檢索的TextBox擴充控件-使用

<a href="http://files.cnblogs.com/whitewolf/sample.rar" target="_blank">執行個體代碼和dll檔案下載下傳</a>

支援拼音檢索的TextBox擴充控件-使用