We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Want to be add custom control on sfDataGrid below the header as extra header.


He All,

Please help me out from below situation,

  • Want to be add custom control on sfDataGrid (with WPF) below the header as extra header.
  • Ability to add controls / templates to unbound data row.
  • Based on custom control change event want to be change value of specific column.

Please find the attached file for more details.


Attachment: sfDataGrid_a9abcca7.zip

3 Replies

SR Sivakumar R Syncfusion Team February 11, 2016 01:37 AM UTC

Hi Pranav,

Your requirement can be achieved by writing custom renderer using ComboBox. Currently we are preparing sample. We will provide update by 11th February, 2016.

Thanks,
Sivakumar


JS Jayapradha S Syncfusion Team February 11, 2016 03:28 AM UTC

Hi Pranav,

Thank you for using Syncfusion products.

You can achieve your requirement by customizing the GridUnBoundRowCellRenderer and you can load the ComboBox as EditElement of GridUnboundRowCell. While changing the item in CombobBox as shared in your screenshot, Salary column will be updated through CurrencyConverter as shown in the below code example,

Code Example:

//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;

            }
        }
   //CurrencyConverter

  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;
        }



Please find the sample from the below location,
Sample Link: http://www.syncfusion.com/downloads/support/forum/121912/ze/CustomUnboundGridCellRenderer1520394619

Please find the UG link below,
UG Link: http://help.syncfusion.com/wpf/sfdatagrid/unbound-rows#custom-renderer
Kindly let us know if you require further assistance on this.

Regards,
Jayapradha


JS Jayapradha S Syncfusion Team February 11, 2016 04:22 PM UTC

Hi Pranav,

We have made some changes in our previous sample to achieve your requirement. Please find the modified code example below,

Code Example:

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));

                }

            }

        }


Find the modified sample from the below location,

Sample Link: http://www.syncfusion.com/downloads/support/forum/121912/ze/CustomUnboundGridCellRenderer-1046764430

Kindly let us know if you have any query.

Regards,
Jayapradha

Loader.
Live Chat Icon For mobile
Up arrow icon