C#
  Home arrow C# arrow Automatic Row Height in DataGrids
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Automatic Row Height in DataGrids
By: Wouter van Vugt
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 19
    2004-01-14

    Table of Contents:
  • Automatic Row Height in DataGrids
  • The Problems Faced with the DataGrids
  • DataGrid Solutions and Article's Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Automatic Row Height in DataGrids


    (Page 1 of 3 )

    It looks like everyone is annoyed with the CSharp implementation of Windows controls. Textboxes, combos and DataGrids are popping up like mushrooms. After building a graphical debugging tool, I too became annoyed with one control in particular; the DataGrid. In this article, building a customized DataGrid that is capable of automatically resizing the column’s width and the row’s height will be achieved.  As a bonus, I will throw in the capability of hiding and showing columns on demand.

    There are loads of things that this control has built in: data binding, some events, and a professional view are available. Next to that, there are also a lot of customized implementations available for adding combo boxes to the grid, or making the columns automatically size their widths. But despite all of this, there is, at least, one thing that is still not found in the feature set.

    Auto sizing row heights is the key phrase. After using the DataGrid I found that the rows do not resize automatically. A multiple line text entry shows as a single-lined row! Look at the picture below to see what the DataGrid looks like in its normal state.

    Don’t worry about the ugly buttons on top (Filter & Add), as this is the picture of the demo application without the autosizing enabled.  The buttons are simply for showing the height calculation still works while adding, or filtering, the rows in autosizing mode.

    The grid is displaying a typed dataset I made for the debugging tool.  Notice the words ‘long’ and ‘medium’?  Yup, there’s more data down there somewhere. The ‘long’ lines are actually three lines in length; the ‘medium’ ones are two.  Also, notice the unsightly background shown beside the last column.  This calls for some remodeling of the DataGrid.

    In this article, building a customized DataGrid that is capable of automatically resizing the column’s width and the row’s height will be achieved.  As a bonus, I will throw in the capability of hiding and showing columns on demand.  The picture below shows how the grid will look.  The picture is again taken from the test application included in the download, which is now enabled.

    As you can see the empty space behind the last column is now filled, and it will stay that way while resizing the grid.  Also, the rows are drawn with their correct heights, greatly improving the readability of the data shown.

    More C# Articles
    More By Wouter Van Vugt


     

    C# ARTICLES

    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...
    - Color Transformation in C# GDI+ Programming
    - Exceptions in C#
    - Overriding versus Overloading
    - Value Types and Reference Types
    - Defining Member and Type Visibility
    - Managing Files in C#





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT