Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WPF data grid width property

Posted on 2015-02-16
6
Medium Priority
?
246 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 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 2000 total points
ID: 40612055
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

926 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