internal void CommitValue(object record, string propName, object value) { #if UWP PropertyInfoCollection descriptor = new PropertyInfoCollection(record.GetType()); #else PropertyDescriptorCollection descriptor = TypeDescriptor.GetProperties(record.GetType()); #endif var propertyinfo = descriptor.GetPropertyDescriptor(propName); object convertedValue = null; if (propertyinfo == null) { if (View.IsDynamicBound) { var type = (value == null) ? null : value.GetType(); convertedValue = ValueConvert.ChangeType(value, type, null); if (convertedValue != null || (NullableHelperInternal.IsNullableType(type) && convertedValue == null)) { SetValue(record, propName, convertedValue); } } return; } convertedValue = ValueConvert.ChangeType(value, propertyinfo.PropertyType, null); if (value != null || (NullableHelperInternal.IsNullableType(propertyinfo.PropertyType) && value == null)) { SetValue(record, propName, convertedValue); } }
private static BindingMode CreateBindingForAddNewRow(GridColumn column) { PropertyDescriptorCollection itemproperties = (column.DataGrid != null && column.DataGrid.View != null) ? column.DataGrid.View.GetItemProperties() : null; if (itemproperties == null) { return(BindingMode.TwoWay); } var propDesc = itemproperties.GetPropertyDescriptor(column.MappingName); if (propDesc != null) { #if WPF if (propDesc.IsReadOnly) #else if (propDesc.SetMethod == null || !propDesc.SetMethod.IsPublic) #endif { return(BindingMode.OneWay); } } else if (propDesc == null) { if (column.AllowEditing && column.CanEditCell()) { return(BindingMode.TwoWay); } return(BindingMode.OneWay); } return(BindingMode.TwoWay); }
private static BindingMode SetBindingMode(GridColumnBase column, PropertyPath path) { var isModeSet = false; var bindingMode = BindingMode.TwoWay; PropertyDescriptorCollection itemproperties = null; if (column.GridBase != null) { if (column.GridBase is SfTreeGrid) { var SfTreeGrid = (column.GridBase as SfTreeGrid); if (SfTreeGrid.View != null) { itemproperties = SfTreeGrid.View.GetItemProperties(); } } else { var sfDataGrid = (column.GridBase as SfDataGrid); if (sfDataGrid.View != null) { itemproperties = sfDataGrid.View.GetItemProperties(); } } } if (itemproperties != null) { var propDesc = itemproperties.GetPropertyDescriptor(column.MappingName); if (propDesc != null) { #if WPF bindingMode = propDesc.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay; #else bindingMode = (propDesc.SetMethod == null || !propDesc.SetMethod.IsPublic) ? BindingMode.OneWay : BindingMode.TwoWay; #endif isModeSet = true; } } //While implementing the IDataErroInfo, will generate Error read only property. Based on this property created a column when AutoGenerateColumn is True. //so that mode will be reset based on AllowEditing property of that Error column. if (!isModeSet) { if (column.AllowEditing && column.CanEditCell()) { bindingMode = BindingMode.TwoWay; } else { bindingMode = BindingMode.OneWay; } isModeSet = true; } return(bindingMode); }
private void PasteNewRow(string[] records) { foreach (var r in records) { string[] record = Regex.Split(r, @"\t"); var provider = this.dataGrid.View.GetPropertyAccessProvider(); var rowData = (this.dataGrid.View as CollectionViewAdv)?.CurrentAddItem; var addNewRowController = this.dataGrid.GetAddNewRowController(); if (rowData == null) { var newRow = addNewRowController.AddNew(); } rowData = (this.dataGrid.View as CollectionViewAdv).CurrentAddItem; var rowColumnIndex = this.dataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex; rowColumnIndex.RowIndex = addNewRowController.GetAddNewRowIndex(); if (rowData == null) { return; } //Paste the copied row in each cell. foreach (var column in this.dataGrid.Columns) { var cellText = provider.GetValue(rowData, column.MappingName); if (cellText == null) { PropertyDescriptorCollection typeInfos = this.dataGrid.View.GetItemProperties(); var typeInfo = typeInfos.GetPropertyDescriptor(column.MappingName); } CommitValue(rowData, column, provider, record[this.dataGrid.Columns.IndexOf(column)]); } this.dataGrid.MoveCurrentCell(rowColumnIndex); addNewRowController.CommitAddNew(); } }
/// <summary> /// Gets the corresponding property type for the specified row data and column. /// </summary> /// <param name="column"> /// The corresponding column to get property type. /// </param> /// <param name="rowData"> /// The corresponding row data to get property type. /// </param> /// <returns> /// Returns the corresponding property type. /// </returns> protected virtual Type GetPropertyType(object rowData, TreeGridColumn column) { if (this.TreeGrid.View == null) { return(null); } //Get the Type of particular column var provider = TreeGrid.View.GetPropertyAccessProvider(); #if UWP PropertyInfoCollection typeInfos = null; if (TreeGrid.View is TreeGridUnboundView) { typeInfos = new PropertyInfoCollection(rowData.GetType()); } else { typeInfos = TreeGrid.View.GetItemProperties(); } #else PropertyDescriptorCollection typeInfos = null; if (TreeGrid.View is TreeGridUnboundView) { typeInfos = TypeDescriptor.GetProperties(rowData); } else { typeInfos = TreeGrid.View.GetItemProperties(); } #endif var typeInfo = typeInfos.GetPropertyDescriptor(column.MappingName); if (typeInfo != null) { return(typeInfo.PropertyType); } var cellvalue = provider.GetValue(rowData, column.MappingName); return(cellvalue != null?cellvalue.GetType() : null); }