August 2004 - Posts
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.
I'm out of the office this week doing some .NET mentoring at a client's site. This sort of work always ends up evolving MM .NET since I get a chance to see how developers are using it in building real-world applications. One of the new features in MM .NET that will come from this visit is pick lists for Windows Forms...stay tuned for more information!
Did you know...
You can apply the CLSCompliant attribute on an assembly (or just about any other program element) and have the compiler check if your code is CLS (Common Language System) compliant (which means it works properly when consumed by other .NET languages). For example, we place the following attribute in all MM .NET AssemblyInfo.cs files:
Here are some of the things the compiler checks:
- Class and member names cannot differ only by case. For example, you can't have one property named Counter and another named counter. This is important for cross-language compatibility since VB .NET isn't case sensitive.
- Overloaded class methods cannot differ only by out or ref parameter designations.
- Publicly exposed members cannot start with an underscore ( _ ).
- Operators can't be overloaded
- Unsigned types can't be part of the public interface of a class
Unfortunately, although you can apply the CLSCompliant attribute in VB .NET, the VB .NET compiler doesn't check for CLS compliance.
Microsoft .NET/C# MVP
Whew! I finished integrating the following Infragistics Web Controls with MM .NET today:
We've implemented the MM .NET data binding, security, and localization interfaces on these controls (where each makes sense). I'm impressed with the look and functionality of these controls. If you haven't checked them out yet I recommend it! It will take me a few days to pull together a release, but if you're a current MM .NET developer and would like an early release send us an e-mail (email@example.com) and we'll get it out to you as soon as it's ready.
Did You Know???
In C# the “is” operator can be used to determine if an object is of a particular type. For example:
public void TestMethod(Control cntrl)
if (cntrl is Label)
Label lbl = (Label)cntrl;
Although this works just fine, it isn't efficient because the type of the object is checked twice...once by the “is“ operator and a second time during the cast. The following code which uses the “as” operator is better because the type is only checked once:
public void TestMethod(Control cntrl)
Label lbl = cntrl as Label;
if (lbl != null)
// Processing code
If the control is not a label, the “lbl” variable is null.
So I've entered the Blogosphere!
I've waited a while to start this blog because of “so much to do, so little time”, but I think there's a lot of value in this form of communication. I plan to use this blog for two main purposes:
1. Posting interesting “did you know?” information relevant to all .NET developers
2. Posting information specific to what I'm currently working on (architecting, coding, etc) in our Mere Mortals .NET Framework
Since I am a C# MVP, I decided to create this blog on msmvps.com...thanks to Susan Bradley for making this site available!
So, let's get to it...
I'm back in the office this week after spending the last week at a client's site in Philadelphia doing some C#/.NET training. I enjoy the entire training process...especially seeing the light bulb go on when a student “gets it”...I always show a humor clip at the beginning of each session to keep things lively...at this point I have a huge collection because students continually send me new clips. This was a particularly bright group of developers so we were able to dive in on some deeper .NET topics including creating your own custom events in .NET.
This week I'm back on track integrating Infragistics controls with our MM .NET Framework. In MM .NET we extend the standard .NET Windows and Web Forms controls in three main ways:
1. Automatic data binding
2. User/Role security
Because we implemented this functionality as different interfaces, we can add this same functionality to other third-party controls such as Infragistics by implementing the corresponding MM .NET interfaces.
Did You Know...
OK, here's our first tidbit...
To quickly change all font sizes in VS .NET (including the "unsettable" font sizes such as dialogs and menus), launch Visual Studio .NET from the Start | Run menu using the "/fs" option. For example:
devenv.exe /fs 14
VS .NET retains these font sizes until you set it back. For example:
devenv.exe /fs 11
President, Oak Leaf Enterprises, Inc.