| | |
Hi, caple of general questions
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2007
Posts: 17
Reputation:
Solved Threads: 0
Hi
I have some questions:
1) How can i get the size of the screen ? (not the forum, the
screen borders)
2) How can i resize all the columns in a DataGridView
to the length of their values ? (when using the built in
method, Autoresize, its only make it larger but dont make
it small if the value is shorter then the column)
3) How can i check if a specific KeyBoard key pressed ? (like Up or A buttons)
4) How can i change a specific Column Behavior in a DataGridView ? (like i want that
only the fields of this Column will be limited to 4 digits)
Thanks.
I have some questions:
1) How can i get the size of the screen ? (not the forum, the
screen borders)
2) How can i resize all the columns in a DataGridView
to the length of their values ? (when using the built in
method, Autoresize, its only make it larger but dont make
it small if the value is shorter then the column)
3) How can i check if a specific KeyBoard key pressed ? (like Up or A buttons)
4) How can i change a specific Column Behavior in a DataGridView ? (like i want that
only the fields of this Column will be limited to 4 digits)
Thanks.
Last edited by 1qaz2wsx7; Jul 17th, 2007 at 9:30 am.
•
•
•
•
1) How can i get the size of the screen ? (not the forum, the
screen borders)
•
•
•
•
2) How can i resize all the columns in a DataGridView
to the length of their values ?
c# Syntax (Toggle Plain Text)
public static void AutoSizeColumns( DataGrid grid ) { System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd( grid.Handle ); GridColumnStylesCollection cs = grid.TableStyles[0].GridColumnStyles; object ds = grid.DataSource; for ( int style = 0; style < cs.Count; style++ ) { int rowCount = ( ds is DataView ) ? ( ds as DataView ).Count : ( ds as DataTable ).Rows.Count; string format = "{0}"; if ( cs[style] is DataGridTextBoxColumn ) { format = "{0:" + ( cs[style] as DataGridTextBoxColumn ).Format + "}"; } // The default minimum width is the header text System.Drawing.SizeF maxWidth = g.MeasureString( cs[style].HeaderText, grid.Font ); // Find the widest row in the grid for this column for ( int i = 0; i < rowCount; i++ ) { System.Drawing.SizeF cellWidth = g.MeasureString( string.Format( format, grid[i, style] ), grid.Font ); if ( cellWidth.Width > maxWidth.Width ) { maxWidth = cellWidth; } } cs[style].Width = (int)maxWidth.Width + 8; } g.Dispose(); }
•
•
•
•
3) How can i check if a specific KeyBoard key pressed ? (like Up or A buttons)
•
•
•
•
4) How can i change a specific Column Behavior in a DataGridView ?
Last edited by Hamrick; Jul 17th, 2007 at 9:40 am.
The truth does not change according to our ability to stomach it.
http://msdn2.microsoft.com/en-us/library/default.aspx
^-- Has the answers to all your questions with code examples.
^-- Has the answers to all your questions with code examples.
![]() |
Similar Threads
- Sitewide text links spots wanted (Ad Space for Sale)
- Questions For WebDevelopment =) (HTML and CSS)
- Commands tips and tricks general questions (Mac tips 'n' tweaks)
- JavaScript/DHTML newbie -- general questions (JavaScript / DHTML / AJAX)
- problem when installing Ms visual studio 2k3 (Windows Software)
- Putting A Computer Together HELP (Troubleshooting Dead Machines)
- PC start, but icon not came (Troubleshooting Dead Machines)
Other Threads in the C# Forum
- Previous Thread: hexadecimal convertions
- Next Thread: c# publish problem
| Thread Tools | Search this Thread |
.net access ado.net algorithm animation array barchart bitmap box broadcast buttons c# check checkbox client code color combobox control conversion csharp custom database datagrid datagridview dataset datastructure datetime degrees development draganddrop drawing encryption enum event excel file form format forms function gdi+ grade hash httpwebrequest image index input install java label lisp list listbox mandelbrot math mouseclick mp3 mysql operator path photoshop picturebox pixelinversion post print programming radians regex remote remoting richtextbox safari serialization server sleep snooze socket sql statistics stream string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser windows winforms wpf xml





