Beispiel #1
0
 /// <summary>
 /// 绑定数据到Cell
 /// </summary>
 /// <returns>返回true则表示已处理过,否则将进行默认绑定(通常只针对有Text值的控件)</returns>
 public void BindingCellData()
 {
     if (DataSource != null)
     {
         for (int i = 0; i < Columns.Count; i++)
         {
             DataGridViewColumnEntity com = Columns[i];
             var cs = this.panCells.Controls.Find("lbl_" + com.DataField, false);
             if (cs != null && cs.Length > 0)
             {
                 var pro = DataSource.GetType().GetProperty(com.DataField);
                 if (pro != null)
                 {
                     var value = pro.GetValue(DataSource, null);
                     if (com.Format != null)
                     {
                         cs[0].Text = com.Format(value);
                     }
                     else
                     {
                         cs[0].Text = value.ToStringExt();
                     }
                 }
             }
         }
     }
     foreach (Control item in this.panCells.Controls)
     {
         if (item is IDataGridViewCustomCell)
         {
             IDataGridViewCustomCell cell = item as IDataGridViewCustomCell;
             cell.SetBindSource(DataSource);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UCTransfer"/> class.
 /// </summary>
 public UCTransfer()
 {
     InitializeComponent();
     LeftColumns     = new DataGridViewColumnEntity[0];
     RightColumns    = new DataGridViewColumnEntity[0];
     LeftDataSource  = new object[0];
     RightDataSource = new object[0];
 }
Beispiel #3
0
        /// <summary>
        /// 绑定数据到Cell
        /// </summary>
        /// <returns>返回true则表示已处理过,否则将进行默认绑定(通常只针对有Text值的控件)</returns>
        public void BindingCellData()
        {
            for (int i = 0; i < Columns.Count; i++)
            {
                DataGridViewColumnEntity com = Columns[i];
                var cs = this.panCells.Controls.Find("lbl_" + com.DataField, false);
                if (cs != null && cs.Length > 0)
                {
                    var pro = DataSource.GetType().GetProperty(com.DataField);
                    if (pro != null)
                    {
                        var value = pro.GetValue(DataSource, null);
                        if (com.Format != null)
                        {
                            cs[0].Text = com.Format(value);
                        }
                        else
                        {
                            cs[0].Text = value.ToStringExt();
                        }
                    }
                }
            }
            foreach (Control item in this.panCells.Controls)
            {
                if (item is IDataGridViewCustomCell)
                {
                    IDataGridViewCustomCell cell = item as IDataGridViewCustomCell;
                    cell.SetBindSource(DataSource);
                }
            }
            panLeft.Tag = 0;
            var proChildrens = DataSource.GetType().GetProperty("Childrens");

            if (proChildrens != null)
            {
                var value = proChildrens.GetValue(DataSource, null);
                if (value != null)
                {
                    int intSourceCount = 0;
                    if (value is DataTable)
                    {
                        intSourceCount = (value as DataTable).Rows.Count;
                    }
                    else if (typeof(IList).IsAssignableFrom(value.GetType()))
                    {
                        intSourceCount = (value as IList).Count;
                    }
                    if (intSourceCount > 0)
                    {
                        panLeft.BackgroundImage = Properties.Resources.caret_right;
                        panLeft.Enabled         = true;
                        panChildGrid.Tag        = value;
                    }
                    else
                    {
                        panLeft.BackgroundImage = null;
                        panLeft.Enabled         = false;
                        panChildGrid.Tag        = null;
                    }
                }
                else
                {
                    panLeft.BackgroundImage = null;
                    panLeft.Enabled         = false;
                    panChildGrid.Tag        = null;
                }
            }
            else
            {
                panLeft.BackgroundImage = null;
                panLeft.Enabled         = false;
                panChildGrid.Tag        = null;
            }
        }