DevExpress控件库---TokenEdit控件使用

 


 

DevExpress控件库---TokenEdit控件使用

用到的基础数据:

 

 public class Product
    {
        public int Id { get; set; }
        public string Model { get; set; }
        public string Name { get; set; }
    }
   public class Entility 
   {
       private static string GetChar(int number)
       {
           string[] array = new string[] { "A","B","C","D","E","F","G","H","I"};
           string result = array[number % 9];
           return result;
       }
       private static string GetName(int number)
       {
           string[] array = 
           {
               "Unitch数据采集器","MS扫描枪","105SL","TSC","PH880","MS320便携式打印机","PA700","DSX800电脑","HP打印机"
           };
           string result = array[number % 9];
           return result;
       }

       public static List<Product> GetProductList() 
       {
           List<Product> list = new List<Product>();
           for (int i = 0; i < 200; i++)
           {
               Product product = new Product() 
               {
                   Id=100+i,Model=GetChar(i)+i.ToString()+"DLJ",Name=GetName(i)+i.ToString()
               };
               list.Add(product);
           }
           return list;
       }
       public static DataTable GetDataTable() 
       {
           DataTable dt = new DataTable();
           dt.Columns.Add("Id",typeof(System.Int32));
           dt.Columns.Add("Model", typeof(System.String));
           dt.Columns.Add("Name", typeof(System.String));
           for (int i = 0; i < 200; i++)
           {
               DataRow dr = dt.NewRow();
               dr["Id"] = 100 + i;
               dr["Model"] = GetChar(i) + i.ToString() + "DLJ";
               dr["Name"] = GetName(i) + i.ToString();
               dt.Rows.Add(dr);
           }
           return dt;
       }
   }

 

 

 

一.控件TokenEdit进行多个数据选择。

TokenEdit数据绑定:

            List<Product> list = Entility.GetProductList();
            foreach (var item in list)
            {
                TokenEditToken token = new TokenEditToken() 
                {
                    Value=item.Id,Description=item.Name
                };
                tokenEdit1.Properties.Tokens.Add(token);
            }
     //值与值直接的分割符
            tokenEdit1.Properties.EditValueSeparatorChar = ',';

            string text = tokenEdit1.EditText;//以,分割的 item.Name
            string value = tokenEdit1.EditValue.ToString();//以,分割的 item.Id


简单介绍到此为止。

posted @ 2015-08-10 11:36    阅读(2757)  评论(0编辑  收藏  举报