473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Autosize + datagrid

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: pa****@rcsoft.pt
Móvel: +351 966931639
Telefone: +351 239708708
Fax: +351 239708701
Tel. Directo: +351 239708705 ext. 401
Jul 21 '05 #1
1 3471
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 inSmart Devices applications or Windows forms application?? That same??
--
Cumprimentos,
David de Passos
--------------------------------------------------------- -----RCSOFT, Lda.
E-Mail: pa****@rcsoft.pt
Móvel: +351 966931639
Telefone: +351 239708708
Fax: +351 239708701
Tel. Directo: +351 239708705 ext. 401
.

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jinx | last post by:
After filling data from a SQL server into a DataTable in a DataSet, I set a DataGrid.DataSource to point to the DataTable. The grid displays the data but all the columns are the same size. How do...
2
by: Tim Wallace | last post by:
I'm using Visual Studio 2003. Is there a way one can cause columns in a DataGrid to autosize? Also, is there a way to cause the last column to take up the remaining space between the end of the...
1
by: Silvia | last post by:
H It is possible in a datagrid by code do the columns autosize? Thanks
1
by: | last post by:
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...
1
by: Gunjan Shah | last post by:
I am developing one Windows application in which i am bindig a data with datagrid. Now i am not able to autosize the columns of datagrid so data looks properly. is there any facility like...
1
by: matthewtech | last post by:
In Visual Studio 2005, using Visual Basic, Is there a way to set the autosize property to false as a standard, and change it to true as needed? Or does it always start out as true when a label ...
8
by: Jordi Rico | last post by:
Hi, I've made the next inherited class in Visual Studio 2005: Public Class LabelEx Inherits System.Windows.Forms.Label Sub New() MyBase.New() Me.ForeColor = Color.Black Me.AutoSize = False...
1
by: SAL | last post by:
How do I get a CELL to autosize a round a Control in a HTML Table? For example, you add a 2 row, 3 column HTML table to your webpage. In the 1st row, you set the colspan=3, then delete the...
2
by: =?Utf-8?B?Qm9i?= | last post by:
In VB.Net 2003 and previous versions new labels were created with AutoSize=False. In VB.Net 2005, new labels are created with AutoSize=True. Why was it changed? Is there somewhere in VB.Net 2005...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.