Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

disallow the user to resize Columns' width in a datagrid

109 views
Skip to first unread message

Joe Abou Jaoude

unread,
May 15, 2005, 6:59:27 AM5/15/05
to

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 ***

Sergey Bogdanov

unread,
May 15, 2005, 8:15:18 AM5/15/05
to
Try to hide header row:- DataGrid.RowHeadersVisible = false.

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

Arun

unread,
May 16, 2005, 3:29:30 AM5/16/05
to
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

Sergey Bogdanov

unread,
May 16, 2005, 4:44:13 AM5/16/05
to
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/microsoft.public.dotnet.framework.compactframework/browse_frm/thread/99e5d7f8500d3d43/e72245ecfafa1c65#e72245ecfafa1c65

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

Joe Abou Jaoude

unread,
May 17, 2005, 5:33:32 AM5/17/05
to

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

Arun

unread,
May 17, 2005, 7:33:19 AM5/17/05
to
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

Joe Abou Jaoude

unread,
May 17, 2005, 8:26:34 AM5/17/05
to

That's what I m gonna do...

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

0 new messages