/// <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) { if (DataSource is DataRow) { DataRow row = DataSource as DataRow; if (com.Format != null) { cs[0].Text = com.Format(row[com.DataField]); } else { cs[0].Text = row[com.DataField].ToStringExt(); } } else { 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.RowCustomEvent += cell_RowCustomEvent; cell.SetBindSource(DataSource); } } }
/// <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(); } } } } } }
/// <summary> /// 绑定数据到Cell /// </summary> 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); } } IsOpened = false; var proChildrens = DataSource.GetType().GetProperty("Childrens"); if (proChildrens != null) { var value = proChildrens.GetValue(DataSource, null); if (value != null) { } else { IsOpened = null; } } else { IsOpened = null; } }
/// <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(); } } } } 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; } }