Solved

WPF data grid width property

Posted on 2015-02-16
6
164 Views
Last Modified: 2015-11-08
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
Comment
Question by:rajeeva_nagaraj
  • 3
  • 2
6 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 40612021
Have you trid binding ActualWidth instead of Width?
0
 

Author Comment

by:rajeeva_nagaraj
ID: 40612037
No i could not see the ActualWidth property
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 40612055
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:rajeeva_nagaraj
ID: 40612096
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 40612105
don't forget that a grid is much more complex then a textbox
0
 

Expert Comment

by:haggard
ID: 41211064
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A short film showing how OnPage and Connectwise integration works.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now