﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Caught in the (dot) Net</title>
    <description>Notes about the interesting (my definition) bits I discover in my programming.  Plus, of course, the occasional tar pit.</description>
    <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/BlogId/6/Default.aspx</link>
    <language>en-GB</language>
    <managingEditor>richard@dynamisys.co.uk</managingEditor>
    <webMaster>richard@dynamisys.co.uk</webMaster>
    <pubDate>Sun, 05 Feb 2012 13:11:40 GMT</pubDate>
    <lastBuildDate>Sun, 05 Feb 2012 13:11:40 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 3.5.1.19887</generator>
    <item>
      <title>Q - Why is caching for my images not working?</title>
      <description>&lt;p&gt;A – Because the browser does not work the way you think it should.  When you press F5 the browser requests the resource it is currently on AND resources directly linked to that page – images.  I set up a web site to serve images with an expiry time.  The idea is that most of the graphics in the skin change rarely.  The browser does not need to down load a fresh copy for each request.&lt;/p&gt;
&lt;p&gt;Fired up fiddler, pressed F5 a few times and got stumped.  Every time the browser was making a fresh request for each image.  When I moved to requesting the page vie a link, even a link on the same page, I saw the cache work as I expected and the requests vanished.&lt;/p&gt;
&lt;p&gt;Doh!&lt;br /&gt;
 &lt;/p&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/99/Q-Why-is-caching-for-my-images-not-working.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/99/Q-Why-is-caching-for-my-images-not-working.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/99/Q-Why-is-caching-for-my-images-not-working.aspx</guid>
      <pubDate>Sun, 21 Aug 2011 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=99</trackback:ping>
    </item>
    <item>
      <title>Force DotNetNuke (DNN) page to display in a specific skin</title>
      <description>&lt;p&gt; Add this (or similar) to the URL&lt;/p&gt;
&lt;p&gt;"?SkinSrc=Portals/_default/Skins/MinimalExtropy/index full"&lt;/p&gt;
&lt;p&gt;I posted this so that I would be able to find it easily for myself.  You can do somthing similar with ContainerSrc too.&lt;/p&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/97/Force-DotNetNuke-DNN-page-to-display-in-a-specific-skin.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/97/Force-DotNetNuke-DNN-page-to-display-in-a-specific-skin.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/97/Force-DotNetNuke-DNN-page-to-display-in-a-specific-skin.aspx</guid>
      <pubDate>Sun, 12 Jun 2011 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=97</trackback:ping>
    </item>
    <item>
      <title>Hierarchical Check Boxes</title>
      <description>&lt;p&gt;Shows how to create a set of hierarchical check boxes.  Checking/unchecking a box at the higher level automatically checks/unchecks the ones at the next level down.&lt;/p&gt;&lt;a href=http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/98/Hierarchical-Check-Boxes.aspx&gt;More...&lt;/a&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/98/Hierarchical-Check-Boxes.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/98/Hierarchical-Check-Boxes.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/98/Hierarchical-Check-Boxes.aspx</guid>
      <pubDate>Sun, 12 Jun 2011 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=98</trackback:ping>
    </item>
    <item>
      <title>Entity Framework Cannot Return an Identity Column when mixed with a DateTime</title>
      <description>&lt;p&gt;I wanted a very simple logging table. I wanted it to be time ordered and I decided to include a smalldatetime column in the primary key.&lt;/p&gt;
&lt;p&gt;This failed badly with Entity Framework. Inserts resulted in a failure message indicating that zero rows were affected. This because a .Net DateTime value is not guaranteed to round trip into SqlServer and back. The SqlServer datetime (and smalldatetime) column types cannot store values with the same precision as the .Net DateTime type.&lt;/p&gt;
&lt;p&gt;EF uses a query like this [1] to store the row and recover the freshly inserted identity column. The DateTime value is ‘rounded’ to suit SQL Server as it is inserted and the Select fails to read the freshly inserted row back because the datetime values are no longer equal.&lt;/p&gt;
&lt;p&gt;I solved this by removing the datetime column from the primary key. It was not crucial for it to be in the primary key.&lt;/p&gt;
&lt;p&gt;Moral – do not mix datetime and identity columns in your primary key.&lt;/p&gt;
&lt;pre&gt;
[1] Entity Framework Generated Query
exec sp_executesql N'insert [dbo].[NewGroupPostalCodes]([PostalCode], 
[Timestamp], [EmailAddress], [Comment])
values (@0, @1, @2, @3)
select [Id]
from [dbo].[NewGroupPostalCodes]
where @@ROWCOUNT &gt; 0 and [PostalCode] = @0 and [Timestamp] = @1 
and [Id] = scope_identity()',N'@0 nvarchar(8),@1 datetime,@2 nvarchar(7),@3
nvarchar(1)',@0=N'cv23 9ee',@1=''2011-05-16 10:49:36:043'',
@2=N'a@b.com',@3=N'w'
&lt;/pre&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/96/Entity-Framework-Cannot-Return-an-Identity-Column-when-mixed-with-a-DateTime.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/96/Entity-Framework-Cannot-Return-an-Identity-Column-when-mixed-with-a-DateTime.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/96/Entity-Framework-Cannot-Return-an-Identity-Column-when-mixed-with-a-DateTime.aspx</guid>
      <pubDate>Tue, 17 May 2011 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=96</trackback:ping>
    </item>
    <item>
      <title>Persuading IIS to serve a Silverlight application</title>
      <description>&lt;p&gt; You need all these MIME types.  Most of them are probably inherited from higher up but I needed to add a couple - could have been a version thing!&lt;/p&gt;
&lt;p&gt;.manifest&lt;br /&gt;
 application/manifest&lt;br /&gt;
 &lt;br /&gt;
.xaml&lt;br /&gt;
 application/xaml+xml&lt;br /&gt;
 &lt;br /&gt;
.dll&lt;br /&gt;
 application/x-msdownload&lt;br /&gt;
 &lt;br /&gt;
.application&lt;br /&gt;
 application/x-ms-application&lt;br /&gt;
 &lt;br /&gt;
.xbap&lt;br /&gt;
 application/x-ms-xbap&lt;br /&gt;
 &lt;br /&gt;
.deploy&lt;br /&gt;
 application/octet-stream&lt;br /&gt;
 &lt;br /&gt;
.xps&lt;br /&gt;
 application/vnd.ms-xpsdocument&lt;br /&gt;
 &lt;br /&gt;
.xap&lt;br /&gt;
 application/x-silverlight-app&lt;/p&gt;
&lt;p&gt;I found &lt;a href="http://stackoverflow.com/questions/2571764/vs2010-code-2104-could-not-download-the-silverlight-application"&gt;this StackOverflow question&lt;/a&gt; useful&lt;/p&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/95/Persuading-IIS-to-serve-a-Silverlight-application.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/95/Persuading-IIS-to-serve-a-Silverlight-application.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/95/Persuading-IIS-to-serve-a-Silverlight-application.aspx</guid>
      <pubDate>Sun, 28 Nov 2010 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=95</trackback:ping>
    </item>
    <item>
      <title>Apology - Did you come on 327 week of 16Feb?</title>
      <description>&lt;p&gt; If you came on the 327 course (C++) I taught at Learning Tree week of 16Feb and have been waiting for your follow up email please accept my apologies.&lt;/p&gt;
&lt;p&gt;Somehow I lost the pile of papers with your email addresses and I have no way of contacting any of you.  Send me an email address and I'll send you the promised material.&lt;/p&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/94/Apology-Did-you-come-on-327-week-of-16Feb.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/94/Apology-Did-you-come-on-327-week-of-16Feb.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/94/Apology-Did-you-come-on-327-week-of-16Feb.aspx</guid>
      <pubDate>Sun, 28 Feb 2010 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=94</trackback:ping>
    </item>
    <item>
      <title>Upgrading My Boot Drive</title>
      <description>&lt;p&gt;Just one way a 30 minutes job can take 5 hours.&lt;/p&gt;&lt;a href=http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/93/Upgrading-My-Boot-Drive.aspx&gt;More...&lt;/a&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/93/Upgrading-My-Boot-Drive.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/93/Upgrading-My-Boot-Drive.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/93/Upgrading-My-Boot-Drive.aspx</guid>
      <pubDate>Sat, 16 Jan 2010 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=93</trackback:ping>
    </item>
    <item>
      <title>How to show a subset of lookup values in a DropDownColumn</title>
      <description>&lt;p&gt;&lt;span style="text-decoration:underline"&gt;&lt;strong&gt;DataGridView – how to show a subset in a DropDownColumn
&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;The standard approach is to add event handlers for CellBeginEdit and CellEndEdit.  In CellBeginEdit a new datasources is bound to the dropdown and in CellEndEdit the binding is reversed.  Here is a sample from the DataGridVew FAQ.
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;&lt;span style="color:blue"&gt;private&lt;/span&gt;
			&lt;span style="color:blue"&gt;void&lt;/span&gt; dataGridView1_CellBeginEdit(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender,&lt;br/&gt;         &lt;span style="color:navy"&gt;&lt;strong&gt;DataGridViewCellCancelEventArgs&lt;/strong&gt;&lt;/span&gt; e)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;{
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:blue"&gt;if&lt;/span&gt; (e.ColumnIndex == territoryComboBoxColumn.Index)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;    {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:green"&gt;// Set the combobox cell datasource to the filtered BindingSource
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:navy"&gt;&lt;strong&gt;DataGridViewComboBoxCell&lt;/strong&gt;&lt;/span&gt; dgcb = (&lt;span style="color:navy"&gt;&lt;strong&gt;DataGridViewComboBoxCell&lt;/strong&gt;&lt;/span&gt;)dataGridView1&lt;br/&gt;                        [e.ColumnIndex, e.RowIndex];
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;        dgcb.DataSource = filteredTerritoriesBS;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:green"&gt;// Filter the BindingSource based upon the region selected
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:blue"&gt;this&lt;/span&gt;.filteredTerritoriesBS.Filter = &lt;span style="color:maroon"&gt;"RegionID = "&lt;/span&gt; +
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:blue"&gt;this&lt;/span&gt;.dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString();
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;    }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;}
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;&lt;span style="color:blue"&gt;private&lt;/span&gt;
			&lt;span style="color:blue"&gt;void&lt;/span&gt; dataGridView1_CellEndEdit(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, &lt;span style="color:navy"&gt;&lt;strong&gt;DataGridViewCellEventArgs&lt;/strong&gt;&lt;/span&gt; e)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;{
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:blue"&gt;if&lt;/span&gt; (e.ColumnIndex == &lt;span style="color:blue"&gt;this&lt;/span&gt;.territoryComboBoxColumn.Index)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;    {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:green"&gt;// Reset combobox cell to the unfiltered BindingSource
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:navy"&gt;&lt;strong&gt;DataGridViewComboBoxCell&lt;/strong&gt;&lt;/span&gt; dgcb = (&lt;span style="color:navy"&gt;&lt;strong&gt;DataGridViewComboBoxCell&lt;/strong&gt;&lt;/span&gt;)dataGridView1&lt;br/&gt;                        [e.ColumnIndex, e.RowIndex];
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;        dgcb.DataSource = territoriesBindingSource; &lt;span style="color:green"&gt;//unfiltered
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;
			&lt;span style="color:blue"&gt;this&lt;/span&gt;.filteredTerritoriesBS.RemoveFilter();
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;    }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;}&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;In general this approach leads to some code repetition and adds to the general clutter of a Windows Form that uses a DataGridView.  It gets EMORMOUSLY more cluttered if there are multiple columns with DropDown's involved.
&lt;/p&gt;&lt;p&gt;This helper class presents a more general approach I used in a recent project.  The project specified many dropdowns which should only present the user with 'Active' options.  The relevant database lookup tables have an IsActive boolean column to distinguish active and inactive rows.  The prime data tables do have a mixture of active and inactive values.
&lt;/p&gt;&lt;p&gt;The first problem is that the DataGridView requires that a DropDown contain the value held by its prime row.  So it is not safe to populate the Dropdown with only active values.
&lt;/p&gt;&lt;p&gt;The basic strategy (see the comments in the code) is:
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Find the cell being edited
&lt;/li&gt;&lt;li&gt;Save the Value and FormattedValue
&lt;/li&gt;&lt;li&gt;Find the original DataSource bound to the dropdown (this source must include both active and inactive entries) the code assumes this source is a DataTable
&lt;/li&gt;&lt;li&gt;Create a new DataTable with only the pruned list of entries in it
&lt;/li&gt;&lt;li&gt;If needed add the Value and FormattedValue to the DataTable because the DataGridView will be upset if it's not there.  Annotate the FormattedValue to discourage the user from choosing it.
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Here is the code.
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;public&lt;/span&gt;
			&lt;span style="color:blue"&gt;enum&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;ActiveOnlyDropDownHelperNullOptions&lt;/span&gt; { ForbidNull, AllowNull }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;public&lt;/span&gt;
			&lt;span style="color:blue"&gt;class&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;ActiveOnlyDropDownHelper
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;ActiveOnlyDropDownHelperNullOptions&lt;/span&gt; _nullOptions;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;BindingSource&lt;/span&gt; _originalBindingSource;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataGridViewComboBoxColumn&lt;/span&gt; _column;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataGridView&lt;/span&gt; _dgv;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;string&lt;/span&gt; _exclusionFilter;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;public&lt;/span&gt; ActiveOnlyDropDownHelper(&lt;span style="color:#2b91af"&gt;DataGridView&lt;/span&gt; dgv, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataGridViewComboBoxColumn&lt;/span&gt; column, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;ActiveOnlyDropDownHelperNullOptions&lt;/span&gt; nullOptions)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            : &lt;span style="color:blue"&gt;this&lt;/span&gt;(dgv, column, nullOptions, &lt;span style="color:#a31515"&gt;"IsActive &lt;&gt; true"&lt;/span&gt;)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;        {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;        }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;public&lt;/span&gt; ActiveOnlyDropDownHelper(&lt;span style="color:#2b91af"&gt;DataGridView&lt;/span&gt; dgv, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataGridViewComboBoxColumn&lt;/span&gt; column, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;ActiveOnlyDropDownHelperNullOptions&lt;/span&gt; nullOptions, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;string&lt;/span&gt; exclusionFilter)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;        {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            dgv.CellBeginEdit += dgv_CellBeginEdit;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            dgv.CellEndEdit += dgv_CellEndEdit;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            _nullOptions = nullOptions;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            _column = column;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            _dgv = dgv;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            _exclusionFilter = exclusionFilter;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;        }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;        
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;private&lt;/span&gt;
			&lt;span style="color:blue"&gt;void&lt;/span&gt; dgv_CellBeginEdit(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataGridViewCellCancelEventArgs&lt;/span&gt; e)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;        {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;if&lt;/span&gt; (e.ColumnIndex == _column.Index)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// Grab the cell we are working in
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataGridViewComboBoxCell&lt;/span&gt; dgcb = (&lt;span style="color:#2b91af"&gt;DataGridViewComboBoxCell&lt;/span&gt;)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    _dgv[e.ColumnIndex, e.RowIndex];
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// Grab the current value and its displayedvalue
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;object&lt;/span&gt; currentValue = dgcb.Value;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;object&lt;/span&gt; currentFormattedValue = dgcb.FormattedValue;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// Get the original data bound to the lookup combo 
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// - assumes it was bound to a DataTable
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// via a BindingSource
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                _originalBindingSource = (&lt;span style="color:#2b91af"&gt;BindingSource&lt;/span&gt;)dgcb.DataSource;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataTable&lt;/span&gt; dt = (&lt;span style="color:#2b91af"&gt;DataTable&lt;/span&gt;)_originalBindingSource.DataSource;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// Copy that DataTable so we can change it
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                dt = dt.Copy();
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;if&lt;/span&gt; (_nullOptions == 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;ActiveOnlyDropDownHelperNullOptions&lt;/span&gt;.AllowNull)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;var&lt;/span&gt; row = dt.NewRow();
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    row[dgcb.ValueMember] = &lt;span style="color:#2b91af"&gt;DBNull&lt;/span&gt;.Value;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    row[dgcb.DisplayMember] = &lt;span style="color:#a31515"&gt;"Null"&lt;/span&gt;;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    dt.Rows.Add(row);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// Remove the rows that are unwanted
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataRow&lt;/span&gt;[] deadRows = dt.Select(_exclusionFilter);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;foreach&lt;/span&gt;(&lt;span style="color:blue"&gt;var&lt;/span&gt; deadRow &lt;span style="color:blue"&gt;in&lt;/span&gt; deadRows)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    dt.Rows.Remove(deadRow);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// The DataGridView will throw an exception if the 
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// prime data has a look up value that's not in the
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// dropdown's list. 
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// If the current value is missing from the drop down then 
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// add it - with an anotation
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;if&lt;/span&gt; (dt.Select(dgcb.ValueMember + &lt;span style="color:#a31515"&gt;" = "&lt;/span&gt; + currentValue).Length
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    == 0)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;var&lt;/span&gt; row = dt.NewRow();
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    row[dgcb.ValueMember] = currentValue;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    row[dgcb.DisplayMember] = currentFormattedValue + 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#a31515"&gt;" (Inactive)"&lt;/span&gt;;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    dt.Rows.Add(row);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// Bind the dropdown to the pruned list.
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                dgcb.DataSource = dt;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;        }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;private&lt;/span&gt;
			&lt;span style="color:blue"&gt;void&lt;/span&gt; dgv_CellEndEdit(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataGridViewCellEventArgs&lt;/span&gt; e)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;        {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;if&lt;/span&gt; (e.ColumnIndex == _column.Index)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;// Return the original BindingSource
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataGridViewComboBoxCell&lt;/span&gt; dgcb = (&lt;span style="color:#2b91af"&gt;DataGridViewComboBoxCell&lt;/span&gt;)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                    _dgv[e.ColumnIndex, e.RowIndex];
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                dgcb.DataSource = _originalBindingSource;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;            }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;        }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;And here is an example of how to use it.  Note you don't even need to save the object reference.  When the event handlers are attached to the DataGridView that will keep the object alive.  If you have multiple dropdown columns in the grid you can keep piling these on.
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;ActiveOnlyDropDownHelper&lt;/span&gt;(partDataGridView, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;                dataGridViewDropDownColumn3, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;ActiveOnlyDropDownHelperNullOptions&lt;/span&gt;.AllowNull, 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:#a31515"&gt;"ID = 30"&lt;/span&gt;);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;Enjoy!&lt;/p&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/91/How-to-show-a-subset-of-lookup-values-in-a-DropDownColumn.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/91/How-to-show-a-subset-of-lookup-values-in-a-DropDownColumn.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/91/How-to-show-a-subset-of-lookup-values-in-a-DropDownColumn.aspx</guid>
      <pubDate>Tue, 18 Aug 2009 13:01:24 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=91</trackback:ping>
    </item>
    <item>
      <title>SQL Server, DateTime values and string formats for Dates</title>
      <description>&lt;p&gt;I've been working with a group who inherited some bad code when the software house supplying them went bust.  When the application added or updated data in SQL Server sometimes date values were accepted in US format and sometimes in UK format.  On the Test server it was one way and on the Live it was the other.&lt;/p&gt;
&lt;p&gt;It's never good when live and test have different configurations but applications often need to work properly regardless of details like date format configurations.  The solution is to use parameters properly.  I wrote about it here. &lt;a href="http://www.dynamisys.co.uk/ForumsBlogs/Forums/tabid/299/forumid/16/scope/threads/Default.aspx"&gt;http://www.dynamisys.co.uk/ForumsBlogs/Forums/tabid/299/forumid/16/scope/threads/Default.aspx&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/90/SQL-Server-DateTime-values-and-string-formats-for-Dates.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/90/SQL-Server-DateTime-values-and-string-formats-for-Dates.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/90/SQL-Server-DateTime-values-and-string-formats-for-Dates.aspx</guid>
      <pubDate>Sat, 11 Jul 2009 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=90</trackback:ping>
    </item>
    <item>
      <title>Using a generic method to achieve a cast</title>
      <description>&lt;p&gt;I just wrote about using a generic extension method as an alternative casting syntax.  I've been using it in some code I've been working on.  I like it.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.dynamisys.co.uk/ForumsBlogs/Forums/tabid/299/forumid/16/postid/1148/scope/posts/Default.aspx"&gt;Find it in the Forum (click here)&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/88/Using-a-generic-method-to-achieve-a-cast.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/88/Using-a-generic-method-to-achieve-a-cast.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/88/Using-a-generic-method-to-achieve-a-cast.aspx</guid>
      <pubDate>Wed, 04 Feb 2009 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.dynamisys.co.uk/DesktopModules/Blog/Trackback.aspx?id=88</trackback:ping>
    </item>
  </channel>
</rss>
