Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

WPF data grid width property

Hi,

I am using WPF data grid in one of my projects, I have 2 columns in the datagrid. I have to set the width of each column dynamically. I mean i have 2 properties called Col1Width and col2 Width

Ex.

Public int Col1Width{get; set;}
public int col2Width{get;set;}

i will set the values to Col1Width and Col2Width in the constructor.

in my Xaml, I have written the below statement

<datagrid>
    <datagridtextcolumn header="Col 1" width="{Binding Path=Col1Width, Mode=TwoWay}"
    <datagridtextcolumn header="Col 2" width="{Binding Path=Col2Width, Mode=TwoWay}"
</datagrid>

But i am unable to get the column width changed. Can anyone guide me in getting the above requirement

Thanks,
Raj
0
rajeeva_nagaraj
Asked:
rajeeva_nagaraj
  • 3
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
Have you trid binding ActualWidth instead of Width?
0
 
rajeeva_nagarajAuthor Commented:
No i could not see the ActualWidth property
0
 
Éric MoreauSenior .Net ConsultantCommented:
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rajeeva_nagarajAuthor Commented:
Is it necessary to go for dependencyobject?

with the below code, i can able to set the width to a textbox. But i am not getting the same for datagrid column

width="{Binding Path=Col2Width, Mode=TwoWay}
0
 
Éric MoreauSenior .Net ConsultantCommented:
don't forget that a grid is much more complex then a textbox
0
 
haggardCommented:
It looks like the data property is an int. Width is a double and this will cause a binding error in a GridViewColumn width.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now