473,847 Members | 2,318 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Autosize + datagrid

How I can autosize a DataGrid after then associate a Datasource=Data set in
Smart Devices applications or Windows forms application?? That same??

David de Passos
E-Mail: pa****@rcsoft.p t
Móvel: +351 966931639
Telefone: +351 239708708
Fax: +351 239708701
Tel. Directo: +351 239708705 ext. 401
Jul 21 '05 #1
1 3512
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.

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

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

System.Drawing. Rectangle rect1 = this.GetCellBou nds(0,

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

// to the base.OnMouseDow n 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.MouseEven tArgs me = new
System.Windows. Forms.MouseEven tArgs
(System.Windows .Forms.MouseBut tons.Left, 2, X, Y, 0);

base.OnMouseDow n(me);
Finally call this method from your client application and
pass the column id of the column you want to autoresize.
Puneet Taneja
-----Original Message-----
How I can autosize a DataGrid after then associate a Datasource=Data set inSmart Devices applications or Windows forms application?? That same??
Cumprimentos ,
David de Passos
--------------------------------------------------------- -----RCSOFT, Lda.
E-Mail: pa****@rcsoft.p t
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

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 I get the colums to adjust their width automatically so that the user does not have to double-click the columns header border. I would apreciate any help. I'm using VisualBasic .NET v7 - 2003 Thanks
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 column and the right edge of the DataGrid? And finally, is there a way to remove the row that permits a user to add data? I looked in the Help, but was unable to discern the answers to the aforementioned questions. Tim
by: Silvia | last post by:
H It is possible in a datagrid by code do the columns autosize? Thanks
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 -------------------------------------------------------------- RCSOFT, Lda.
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 autosizing the columns? if yes then wat to do? and if not then what is the solution?
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 is brought in to a form? This is probably a very basic question, but I appreciate any help anyone can offer.
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 Me.Height = 16
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 excess columns. Now the 1st row should look like it has only 1 cell, and the 2nd row has 3 cells. Now add a Web Forms DataGrid in row, and add a Web Forms Button in the middle cell of row 2. Now, when I try to resize the row, I can’t seem to get...
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 where this defalut can be changed back to Autosize=False. I am not interested in creating my own custom class to fix the problem.
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.