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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DataGrid Binding

Thread ID:





126037 Sep 20,2016 09:25 AM UTC Sep 21,2016 12:49 PM UTC Xamarin.Forms 1
Tags: SfDataGrid
Thomas Gruener
Asked On September 20, 2016 09:25 AM UTC

How can I do the Binding of my Converter with the DataGrid in Code, and how can I bind on ColumnGeneration?

this doesn't work for me:
col.DisplayBinding = new Binding("Vals[" + key.Key + "]", BindingMode.OneWay, new GridCurrencyConverter());

Here is my code:

public class GridCurrencyConverter : IValueConverter
        //check data and replace "-1" with "-"
        public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
                string tmp = Helper.DataGridValueConverter(value.ToString());

                if (tmp != "-" && (tmp.Contains(".") || tmp.Contains(",")))
                    double val = System.Convert.ToDouble(value);
                    val = Math.Round(val);
                    return Helper.ConvertValue(val.ToString());

                return tmp;
            catch (Exception)
                return value;

        //keep current data
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)
            return value;

 private SfDataGrid CreateDataGrid(List<DynamicData<string, object>> dynData)
            List<Dictionary<string, string>> objList = CreateGridItems(dynData);

            ViewModel vm = new ViewModel();
            vm.dataGridDetails = new ObservableCollection<DataGridItem>();

            foreach(Dictionary<string, string> di in objList)
                vm.dataGridDetails.Add(new DataGridItem() { Vals = di });

            dGrid = new SfDataGrid();
            dGrid.ItemsSource = vm.DataGridDetails;
            dGrid.ColumnSizer = ColumnSizer.None;
            dGrid.AlternationCount = 2;
            dGrid.GridStyle.AlternatingRowColor = Color.FromHex("#d3d3d3");

            dGrid.AutoGenerateColumns = false;
            dGrid.AllowSorting = true;

            foreach (KeyValuePair<string, string> key in objList[0])
                GridTextColumn col = new GridTextColumn();
                col.MappingName = "Vals[" + key.Key + "]";
                col.HeaderText = SprocEvaluator.TagConverter(key.Key);
                col.Width = 120d;
//this doesn't work: Cannot convert from GridCurrencyConverter to Xamarin.Forms.IValueConverter????
                col.DisplayBinding = new Binding("Vals[" + key.Key + "]", BindingMode.OneWay, new GridCurrencyConverter());

            return dGrid;

Appreciate any help.

Divakar Subramaniam [Syncfusion]
Replied On September 21, 2016 12:49 PM UTC

Hi Thomas,   
Thanks for contacting Syncfusion Support.    
We have checked your query. We were not able to reproduce the reported issue and the converter is working fine from our side.   
We have prepared a sample by converting the negative value present in the collection to its equivalent positive value using IValueConverter inGridColumn.DisplayBinding property as per your requirement and you can download the same from the below link.   
In case, if the issue still persists at your end then please do revert with the modified sample reproducing the issue.  


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon