Solved

WPF data grid width property

Posted on 2015-02-16
6
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 70

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 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 40612055
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

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 70

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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net figure out error 3 47
asp.net repeater 2 36
Need to find a web event on the IIS server 4 52
Why am I losing my session variable value 11 39
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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