PC Review


Reply
Thread Tools Rate Thread

disallow the user to resize Columns' width in a datagrid

 
 
Joe Abou Jaoude
Guest
Posts: n/a
 
      15th May 2005

HI,
Can I disallow the user to resize Columns' width in a datagrid ?
I fixed the width in the TableStyles.
Regards


*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Sergey Bogdanov
Guest
Posts: n/a
 
      15th May 2005
Try to hide header row:- DataGrid.RowHeadersVisible = false.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Joe Abou Jaoude wrote:
> HI,
> Can I disallow the user to resize Columns' width in a datagrid ?
> I fixed the width in the TableStyles.
> Regards
>
>
> *** Sent via Developersdex http://www.developersdex.com ***

 
Reply With Quote
 
Arun
Guest
Posts: n/a
 
      16th May 2005
Write a DataGrid MouseUp event for ColumnResize and RowResize
Try the code below.

private void dataGrid1_MouseUp(object sender, MouseEventArgs e)
{
DataGrid myGrid=(DataGrid)sender;
DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X,e.Y);

if(myHitInfo.Type == DataGrid.HitTestType.ColumnResize)
{
//Do Nothing
}
}

Hope this helps,
Cheers,
Arun.
www.innasite.com

 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      16th May 2005
Well, this solution is a bit complicated than just remove header row
though it works either with a small correction:- instead of handle
MouseUp event you have to write new class that derived from DataGrid,
*override* method OnMouseDown then suppress base implementation for
ColumnResize types. For more information see [1]. Here you are C#
implementation:

public class DataGridWithFixedColumnWidth : DataGrid
{
protected override void OnMouseDown(MouseEventArgs e)
{
DataGrid.HitTestInfo hitInfo = HitTest(e.X, e.Y);
// suppress ColumnResize event
if (hitInfo.Type == DataGrid.HitTestType.ColumnResize) return;

base.OnMouseDown (e);
}
}

[1]
http://groups-beta.google.com/group/...2245ecfafa1c65

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Arun wrote:
> Write a DataGrid MouseUp event for ColumnResize and RowResize
> Try the code below.
>
> private void dataGrid1_MouseUp(object sender, MouseEventArgs e)
> {
> DataGrid myGrid=(DataGrid)sender;
> DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X,e.Y);
>
> if(myHitInfo.Type == DataGrid.HitTestType.ColumnResize)
> {
> //Do Nothing
> }
> }
>
> Hope this helps,
> Cheers,
> Arun.
> www.innasite.com
>

 
Reply With Quote
 
Joe Abou Jaoude
Guest
Posts: n/a
 
      17th May 2005


Thankx guys, I'll try both solutions..

a question about HitTestInfo :

can i use this property to disallow a user to select a row in a datagrid
?
here's the problem:
In a datagrid that is used only in view mode,I don't want the user to be
able to change the row selections. For this purpose, I disabled the
datagrid, but the disadvantage of this method is that it prevents the
user to scroll the datagrid, and thus can't see all the records.

regards

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Arun
Guest
Posts: n/a
 
      17th May 2005
Yes there are 8 HitTestType below is the list,
Best way is to write a class as mentioned by Sergey to disable the
datagrid.

DataGrid.HitTestType.Cell
DataGrid.HitTestType.Caption
DataGrid.HitTestType.ColumnHeader
DataGrid.HitTestType.ColumnResize
DataGrid.HitTestType.ParentRows
DataGrid.HitTestType.RowHeader
DataGrid.HitTestType.RowResize
DataGrid.HitTestType.None

block all the HitTestType each with separate condition
Hope this helps,
Cheers,
Arun.
www.innasite.com

 
Reply With Quote
 
Joe Abou Jaoude
Guest
Posts: n/a
 
      17th May 2005

That's what I m gonna do...

I didn't know that HitTestType can be that useful.
that's great

regards

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
New Member
Join Date: Aug 2005
Posts: 1
 
      23rd Aug 2005
I notice you can't do the same with ListView control ! But i badly need to stop the columnresizing there. Can you pro's please help me ?

Appreciated.

BRGDS Rickard
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resize whole datagrid, not only columns! tasiekk@tlen.pl Microsoft ASP .NET 4 24th Aug 2006 03:46 PM
Resize datagrid column width depending upon text enter by user. =?Utf-8?B?cHJhbWF5?= Microsoft Dot NET Framework Forms 0 18th Jul 2005 09:53 AM
Datagrid Column Width Resize Event? Asgorath Microsoft VB .NET 0 28th Sep 2004 05:02 PM
Resize datagrid columns? emde Microsoft ADO .NET 1 12th Apr 2004 07:06 PM
Shortcut key to resize all columns according to data width topstar Microsoft Excel Misc 4 19th Mar 2004 06:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:41 PM.