//customized GridUnBoundRowCellRenderer protected override void OnEditElementLoaded(object sender, RoutedEventArgs e) { var displayValue = combo.SelectedValue; combo = sender as ComboBox; List<string> itemsCollection = new List<string>(); itemsCollection.Add("India"); itemsCollection.Add("USA"); combo.ItemsSource = itemsCollection; combo.SelectionChanged += combo_SelectionChanged; combo.SelectedValue = displayValue.ToString(); }
void combo_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { combo = sender as ComboBox; if (combo != null && combo.SelectedItem != null) { (DataGrid.DataContext as SalesInfoViewModel).DisplayValue = combo.SelectedItem.ToString(); var binding = new Binding(); binding.Converter = new CurrencyConverter(); binding.ConverterParameter = combo.SelectedItem.ToString(); DataGrid.Columns[2].DisplayBinding = binding; DataGrid.Columns[2].ValueBinding = binding; } public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var model = value as SalesByYear; //converts the currency rate of India to USA if (parameter != null && parameter.ToString() == "USA") { return "$" + "" + (double)model.QS2 / 60; } //converts the currency rate of USA to India else if(parameter!=null && parameter.ToString()=="India") { return (double)model.QS2*60; } else return (double)model.QS2;
public MainWindow() { InitializeComponent(); sfDataGrid.QueryUnBoundRow += sfDataGrid_QueryUnBoundRow; sfDataGrid.UnBoundRowCellRenderers.Add("GridUnBoundRowCellTextBoxRendererExt", new GridUnBoundRowCellTextBoxRendererExt()); }
void sfDataGrid_QueryUnBoundRow(object sender, Syncfusion.UI.Xaml.Grid.GridUnBoundRowEventsArgs e) { if (e.UnBoundAction == UnBoundActions.QueryData) { if (e.GridUnboundRow.UnBoundRowIndex == 0 && e.GridUnboundRow.Position == UnBoundRowsPosition.Top) { if (e.RowColumnIndex.ColumnIndex == 2) { e.CellType = "GridUnBoundRowCellTextBoxRendererExt"; e.Value = (sfDataGrid.DataContext as SalesInfoViewModel).DisplayValue; e.Handled = true; } } } else if(e.UnBoundAction == UnBoundActions.CommitData) { if(e.Value!=null) (sfDataGrid.DataContext as SalesInfoViewModel).DisplayValue = e.Value.ToString(); } e.Handled = true; |
void sfDataGrid_QueryUnBoundRow(object sender, Syncfusion.UI.Xaml.Grid.GridUnBoundRowEventsArgs e) { if (e.UnBoundAction == UnBoundActions.QueryData) { if (e.GridUnboundRow.UnBoundRowIndex == 0 && e.GridUnboundRow.Position == UnBoundRowsPosition.Top) { if (e.Column.MappingName=="QS2") { e.CellType = "GridUnBoundRowCellTextBoxRendererExt"; e.Value = (sfDataGrid.DataContext as SalesInfoViewModel).DisplayValue; e.Handled = true; } } } else if(e.UnBoundAction == UnBoundActions.CommitData) { if (e.Column.MappingName == "QS2" && e.Value != null) { var binding = new Binding(); binding.Converter = new CurrencyConverter(); binding.ConverterParameter = e.Value.ToString(); sfDataGrid.Columns[2].DisplayBinding = binding; sfDataGrid.Columns[2].ValueBinding = binding; } } e.Handled = true; }
//CustomizedUnboundRowCellRenderer public override void OnInitializeEditElement(DataColumnBase dataColumn, ComboBox uiElement, object dataContext) { List<string> itemsCollection = new List<string>(); itemsCollection.Add("India"); itemsCollection.Add("USA"); uiElement.ItemsSource = itemsCollection; if(dataColumn.GridUnBoundRowEventsArgs.Value!=null) uiElement.SelectedValue = dataColumn.GridUnBoundRowEventsArgs.Value.ToString(); uiElement.Tag = dataColumn; }
void uiElement_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { var comboBox = sender as ComboBox; if (comboBox != null && comboBox.SelectedItem != null) { if (comboBox != null && comboBox.SelectedItem != null) { (DataGrid.DataContext as SalesInfoViewModel).DisplayValue = comboBox.SelectedItem.ToString(); (comboBox.Tag as DataColumnBase).GridUnBoundRowEventsArgs.Value = comboBox.SelectedItem.ToString(); DataGrid.RaiseQueryUnBoundRow((comboBox.Tag as DataColumnBase).GridUnBoundRowEventsArgs.GridUnboundRow, UnBoundActions.CommitData, (comboBox.Tag as DataColumnBase).GridUnBoundRowEventsArgs.Value, (comboBox.Tag as DataColumnBase).GridColumn, (comboBox.Tag as DataColumnBase).GridUnBoundRowEventsArgs.CellType, new Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex((comboBox.Tag as DataColumnBase).RowIndex, (comboBox.Tag as DataColumnBase).ColumnIndex)); } } } |