Kevin McNeish Blog

All things iOS, Kindle and .NET

Recent Posts

Tags

News

  • First books in my new book series, "iOS App Development for Non-Programmers" are now available! iBookStore: http://itunes.apple.com/us/book/book-1-diving-in-ios-app-development/id558788074?mt=11 Amazon: http://www.amazon.com/dp/B0097N8XBE Amazon: http://www.amazon.com/dp/B0099RQGMQ

Community

Email Notifications

Archives

Windows DataGrid Enhancments

I spent quite a bit of time this week enhancing the MM .NET Windows Forms DataGrid. Here are the enhancements I've made:

  • Added a MultiSelect property that allows developers to specify if a grid should operate in multi-select mode (the default) or single-select mode
  • Added a GetSelectedRows() method that returns a DataSet containing a list of currently selected rows.
  • Added a SelectRowOnCellClick property that specifies if the entire row should be selected when a grid cell is clicked
  • Added a SelectedRowCountChange event to the grid that is automatically fired when the number of selected rows changes. This is useful when you need to enable/disable another UI control (such as an OK button) asitems are selected/deselected.
  • Added an AutoResizeColumns property to the grid that specifies if columns should be resized when the DataGrid is resized. You can resize all columns or specify a single column to be resized.

Regarding the last item, I saw a few solutions on the web that set the size of all columns to the same width and resized them equally. I went a bit further and added logic that resizes the columns proportional to their original sizes. All of this took just a bit of doing to make sure the timing was correct, because the size of the row header and presence of the vertical scroll bar must be taken into account when resizing the columns. What's nice about this solution is you don't have to spend all of the usual “pain in the neck” time getting the column sizes just right at design time. You can set them to a value that's close to what you want, and the resizing logic will automatically resize them proportionately to fill the grid.

Did You Know?

Normally, when you add a new item to a project in VS .NET, if the item is not under the project's root directory structure, it makes a copy of the file locally and adds it to the project.

If you would rather add a link to a file rather than making a local copy, in the Add Existing Item dialog, click the down arrow on the Open button and select Link File from the popup menu.

Kevin McNeish
.NET/C# MVP

 

Comments

KevinMcNeish said:

Hello Kevin,
this are reasonable enhancements.
Is it downloadable anywhere ?
thx, Frank
# November 18, 2004 7:31 AM

KevinMcNeish said:

Hi Kevin,
Is it posssible to get the source for your imlementation?
Cheers,
Mark
# November 23, 2004 1:13 AM

KevinMcNeish said:

Re: Did You Know

The "link file" method doesn't seem to work in web applications.
# December 16, 2004 12:43 PM

KevinMcNeish said:

Is it downloadable anywhere ?
# January 10, 2005 9:24 AM

KevinMcNeish said:

The DataGrid enhancments are part of the MM .NET Framework. You can get an evaluation version at http://www.oakleafsd.com.
# February 26, 2005 8:43 PM

KevinMcNeish said:

You gotta pay for it? Weak. I'll write one and post it for free on Code Project.
# March 3, 2005 12:06 PM

KevinMcNeish said:

datagrid1.select(rowindex)

will select entire row. I dont think we need to pay for this line.
# March 29, 2005 10:11 AM

KevinMcNeish said:

How to disiable the column resize event in windows data grid control..
# April 5, 2005 11:55 PM

KevinMcNeish said:

Developing this framework is his business, why would you be upset that he doesnt give you something for free? I dont think there's an unspoken rule that just because you blog something that its open source.
# April 15, 2005 9:32 AM

TrackBack said:

^_~,pretty good,18showsseeoo!
# April 18, 2005 1:00 AM

TrackBack said:

Windows DataGrid Enhancmentsooeess
# May 25, 2005 5:07 AM

KevinMcNeish said:

TeST
# July 11, 2005 10:30 AM

TrackBack said:

Windows DataGrid Enhancmentsooeess
# July 22, 2005 8:20 PM

TrackBack said:

Windows DataGrid Enhancmentsooeess
# August 3, 2005 9:09 PM

KevinMcNeish said:

It's really nice
# November 11, 2005 12:52 AM

KevinMcNeish said:

i want that
# November 22, 2005 2:14 AM
Leave a Comment

(required) 

(required) 

(optional)
 

(required) 

If you can't read this number refresh your screen
Enter the numbers above: