Solved

WPF data grid width property

Posted on 2015-02-16
6
157 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

19 Experts available now in Live!

Get 1:1 Help Now