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...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

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.  

I have a solution for this stuff:

1. Create dependency property

 public class XceedColumnsBehavior

        #region Attached property

        public readonly static DependencyProperty HideXceedGridColumnsProperty = DependencyProperty.RegisterAttached(
            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;


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
                if (_hidingFieldNames == null)
                 {   _hidingFieldNames = new List<string>();
                return _hidingFieldNames;
                _hidingFieldNames = value;
                OnPropertyChanged(MethodBase.GetCurrentMethod().Name.Remove(0, 4));


Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
33401516 Can be accepted as the solution for binding to Xceed grid column visibility.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.