PC Review


Reply
Thread Tools Rate Thread

Autosize + datagrid

 
 
Guest
Posts: n/a
 
      16th Dec 2003
How I can autosize a DataGrid after then associate a Datasource=Dataset in
Smart Devices applications or Windows forms application?? That same??

--


Cumprimentos,
David de Passos
--------------------------------------------------------------
RCSOFT, Lda.
E-Mail: (E-Mail Removed)
Móvel: +351 966931639
Telefone: +351 239708708
Fax: +351 239708701
Tel. Directo: +351 239708705 ext. 401


 
Reply With Quote
 
 
 
 
Puneet Taneja
Guest
Posts: n/a
 
      17th Dec 2003
Dear David,

One of the ways to autoresize columns in datagrid is to
simulate the behavior of the mouse double click on the
column header border. This solution works perfect unless
you want to write the entire code to resize the columns.

Solution:
Create a control inherited from the DataGrid control and
create a public method with following signature and
implementation:

public void AutoSizeColumn(int colNumber)
{
// The rect1 will contain the bounds of the zeroth cell
at the specified column.

System.Drawing.Rectangle rect1 = this.GetCellBounds(0,
colNumber);

// Basically we need to extract the x and y information
so that the same can be passed

// to the base.OnMouseDown call to simulate the behavior
of double click over a column.

int X = rect1.X + rect1.Width;

int Y = rect1.Y - 5;

// 5 can be taken as a constant as above the cell at
zeroth row of this column will be the column header.

// The height of the column header must be greater than 5.

// For more precision, you can retrieve the header font /
header text and then use Graphics class's

// measurestring method to calculate the height of the
header and then pass y as somewhere

// in the middle of the header's Y + Height.

System.Windows.Forms.MouseEventArgs me = new
System.Windows.Forms.MouseEventArgs
(System.Windows.Forms.MouseButtons.Left, 2, X, Y, 0);

base.OnMouseDown(me);
}


Finally call this method from your client application and
pass the column id of the column you want to autoresize.


Regards,
Puneet Taneja

>-----Original Message-----
>How I can autosize a DataGrid after then associate a

Datasource=Dataset in
>Smart Devices applications or Windows forms

application?? That same??
>
>--
>
>
>Cumprimentos,
>David de Passos
>---------------------------------------------------------

-----
>RCSOFT, Lda.
>E-Mail: (E-Mail Removed)
>Móvel: +351 966931639
>Telefone: +351 239708708
>Fax: +351 239708701
>Tel. Directo: +351 239708705 ext. 401
>
>
>.
>

 
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
autosize DataGrid column Tim Wallace Microsoft C# .NET 2 18th Jul 2005 06:48 PM
Autosize Columns in a datagrid =?Utf-8?B?TWljaGFlbCBPcGVs?= Microsoft Dot NET Compact Framework 1 27th Apr 2005 10:49 AM
Datagrid autosize =?Utf-8?B?U2lsdmlh?= Microsoft VB .NET 1 4th May 2004 12:30 PM
Autosize + Datagrid Microsoft Dot NET Framework 1 16th Dec 2003 05:59 PM
Autosize + Datagrid Microsoft Dot NET Framework Forms 1 16th Dec 2003 05:46 PM


Features
 

Advertising
 

Newsgroups
 


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