hide the columns in Xceed grid with properties

i am using xceed grid for development.

i have 10 columns defined in xamal.. but i want to hide columns dynamically ..i have created bool property for each column and i am trying to bind to visible property of each column..but it isnot working..i mean not hiding...  sample xamal code below...

<xcdg:Column FieldName="IFC" Title="IFC" Width="80"
 Visible="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataGridControl}},Path=IsIFCHidden}"/>

pls help...
                                           
PradeepDumpalaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
alainbrydenConnect With a Mentor Commented:
Funny enough, I ended up having to solve this problem myself.
Not sure how it compares in terms of elegance, but it's very simple to implement and very efficient.

This was my solution:
1. Create the properties or controls controlling column behaviour
2. Handle the property change event or monitor property binding with the following:

void LOBCheckBox_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            LOBByCoverageVM clicked = sender as LOBByCoverageVM;
            try
            {
                dataGrid.Columns[clicked.LobCoverageName].Visible = clicked.IsSelected;
            }
            catch(Exception ex)
            {
                throw new Exception("Column " + clicked.LobCoverageName + " does not exist in the loaded table", ex);
            }
        }

Open in new window

0
 
alainbrydenCommented:
First, just set visible = "False" - does this hide the column as you wanted?
If so then your issue is simply that the binding isn't correct.

Now it looks like you're trying to bind to a property called ISIFCHidden, but your source is a DataGrid, which doesn't make sense, because DataGrids don't have that property. I think maybe you're trying to a bind to a class property?  If that's so you should have (in the code behind your control) this.DataContext = this, and you should not be specifying a RelativeSource at all. Remove that and just use {Binding Path=IsIFCHidden}

Also not that IsIFCHidden better not be a boolean. You're binding the "Visible" Property, which is an enumeration. It has a value of "Visible", "Collapsed", or "Hidden" (most likely) - and IsIFCHidden has to be of the same type as the enumeration used for the Visible property, or else you need to define a converter that converts a boolean true/false into a proper visibility value and include that converter in the binding.

If all this is more complicated than you want it to be you should try instead using a datatrigger on the UIElement.Visibility property of the column. The effect will be the same, but you don't have to worry about the enumeration.

Final piece of advice - look at your Immediate Window! It will tell you when you have bindings that are improperly defined at runtime.

--
Alain
0
 
LIVEEXCommented:
First, the binding is correct. This is binding to Visible not Visibility, so the data type is bool. If you set Visible = False the column will be hidden.  


0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LIVEEXCommented:
I have a solution for this stuff:

1. Create dependency property

 public class XceedColumnsBehavior
    {

        #region Attached property

        public readonly static DependencyProperty HideXceedGridColumnsProperty = DependencyProperty.RegisterAttached(
            "HideXceedGridColumns",
            typeof(IList<string>),
            typeof(XceedColumnsBehavior),
            new UIPropertyMetadata(null, XceedColumnsBehavior.OnHideColumnsChange));

        public static void SetHideXceedGridColumns(DependencyObject target, IList<string> value)
        {
            target.SetValue(XceedColumnsBehavior.HideXceedGridColumnsProperty, value);
        }

        private static void OnHideColumnsChange(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
           if(e.NewValue != null)
           {
               var fieldNames = e.NewValue as IList<string>;
               var grid = target as DataGridControl;
               foreach(var fieldName in fieldNames)
                   grid.Columns[fieldName].Visible = false;
           }
        }

        #endregion
    }


2. In grid binding dependency property to a hide column list

<xcdg:DataGridControl  ItemsSource="{Binding Path=Rfids}"
                                      AllowDrag="False" AllowDrop="False"
                                      AutoCreateColumns="False" ReadOnly="True" SelectionMode="Single"
                                      VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                      attachPro:XceedColumnsBehavior.HideXceedGridColumns="{Binding Path=HidingFieldNames}"
                                      >


3. In data context create a hide list of column

   private IList<string> _hidingFieldNames = null;
        public IList<string> HidingFieldNames
        {
            get
            {
                if (_hidingFieldNames == null)
                 {   _hidingFieldNames = new List<string>();
                        _hidingFieldNames.Add();
                 }
                return _hidingFieldNames;
            }
            set
            {
                _hidingFieldNames = value;
                OnPropertyChanged(MethodBase.GetCurrentMethod().Name.Remove(0, 4));
            }
        }

Done.....!!!!!

0
 
Tom KnowltonWeb developerCommented:
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
alainbrydenCommented:
33401516 Can be accepted as the solution for binding to Xceed grid column visibility.
0
All Courses

From novice to tech pro — start learning today.