﻿<?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.net-programmer.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>Tue, 07 Sep 2010 12:01:05 GMT</pubDate>
    <lastBuildDate>Tue, 07 Sep 2010 12:01:05 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 3.5.1.19887</generator>
    <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.net-programmer.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.net-programmer.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.net-programmer.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.net-programmer.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.net-programmer.co.uk/DesktopModules/Blog/Trackback.aspx?id=88</trackback:ping>
    </item>
    <item>
      <title>Developing as non-admin.  It's not all roses!</title>
      <description>&lt;div&gt;
&lt;p&gt;A year ago I decided to try the delights of developing as a non-admin.  It’s been great, I didn’t regret it.&lt;/p&gt;
&lt;p&gt;My machine has been showing the symptoms of software rot.  Yesterday evening I repaved my machine.  I organize my disk as a partition for the O/S plus software and a separate partition for data.  I did a total ground-zero reinstall of the O/S (Win XP Pro), on a freshly formatted partition.  One effect of that is that my new account has a new SID.  All the old files on my data partition allow me to read them – I’m a User, but they don’t let me delete/write/&lt;wbr&gt;&lt;/wbr&gt;update because my new SID is different to the one they were created with.&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;I think I am going to have to live with manually changing file permission settings for many months to come – I’d be *&lt;strong&gt;very&lt;/strong&gt;* interested to hear of any cute shortcuts to that process.  More important – I’m expecting to have to re-pave again, annually seems about normal for me.  What I'd really like is some ideas on what I can do to stop this problem next time?&lt;/div&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/86/Developing-as-non-admin-Its-not-all-roses.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/86/Developing-as-non-admin-Its-not-all-roses.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/86/Developing-as-non-admin-Its-not-all-roses.aspx</guid>
      <pubDate>Mon, 08 Dec 2008 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.net-programmer.co.uk/DesktopModules/Blog/Trackback.aspx?id=86</trackback:ping>
    </item>
    <item>
      <title>Who is behind 0023222270680?  Feels like a scam.</title>
      <description>&lt;p&gt;Got a text about a parcel?  Ignore it!&lt;/p&gt;&lt;a href=http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/84/Who-is-behind-0023222270680-Feels-like-a-scam.aspx&gt;More...&lt;/a&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/84/Who-is-behind-0023222270680-Feels-like-a-scam.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/84/Who-is-behind-0023222270680-Feels-like-a-scam.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/84/Who-is-behind-0023222270680-Feels-like-a-scam.aspx</guid>
      <pubDate>Sun, 23 Nov 2008 00:00:00 GMT</pubDate>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.net-programmer.co.uk/DesktopModules/Blog/Trackback.aspx?id=84</trackback:ping>
    </item>
    <item>
      <title>First time at the Fringe</title>
      <description>&lt;p&gt;I'm working in Edinburgh this week and it's the Edinburgh Festival time. Definitely &lt;img alt="" src="/Providers/HtmlEditorProviders/Fck/FCKeditor/editor/images/smiley/msn/regular_smile.gif" /&gt;.&lt;/p&gt;
&lt;div&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;span style="font-size: 10pt"&gt;Laura is up here too, ready for next term.  We were planning to go to see Paul Merton's improvisation show, but we only had one ticket.  I'd got the last one when tried to book for both of us.  We hoped we might be able to get a press return.&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;span style="font-size: 10pt"&gt;We couldn’t get a press ticket at the box office, she tried calling in a favour from someone who was working in the venue, but no joy.  So I was just keeping her company in the queue.  A venue worker went past collecting ticket stubs – “I’m just standing here – couldn’t get a ticket.”  Five minutes later she was back – "There’s a guy farther back in the queue with a spare ticket."  He sold it me for a tenner but I'd have given him £15. Whoo-hoo.  I don’t think Laura stopped laughing for a whole hour – it was *&lt;strong&gt;&lt;span style="font-weight: bold"&gt;that&lt;/span&gt;&lt;/strong&gt;* good.  I'd seen them before, but hey - it's improvisation.  They were the same people; the show had much the same basic structure; but wasn't the same show.  Fantastic.  Go see them if you can. &lt;img alt="" src="/Providers/HtmlEditorProviders/Fck/FCKeditor/editor/images/smiley/msn/thumbs_up.gif" /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/div&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/79/First-time-at-the-Fringe.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/79/First-time-at-the-Fringe.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/79/First-time-at-the-Fringe.aspx</guid>
      <pubDate>Mon, 11 Aug 2008 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.net-programmer.co.uk/DesktopModules/Blog/Trackback.aspx?id=79</trackback:ping>
    </item>
    <item>
      <title>And the bus went sailing by</title>
      <description>&lt;p&gt;I've been away this week and using the local bus.  Mostly it's worked pretty well.&lt;/p&gt;&lt;a href=http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/76/And-the-bus-went-sailing-by.aspx&gt;More...&lt;/a&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/76/And-the-bus-went-sailing-by.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/76/And-the-bus-went-sailing-by.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/76/And-the-bus-went-sailing-by.aspx</guid>
      <pubDate>Thu, 19 Jun 2008 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.net-programmer.co.uk/DesktopModules/Blog/Trackback.aspx?id=76</trackback:ping>
    </item>
    <item>
      <title>To IBM for C#</title>
      <description>&lt;p&gt;Having a great time at IBM this week.&lt;/p&gt;&lt;a href=http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/73/To-IBM-for-C.aspx&gt;More...&lt;/a&gt;</description>
      <link>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/73/To-IBM-for-C.aspx</link>
      <author>richard@dynamisys.co.uk</author>
      <comments>http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/73/To-IBM-for-C.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.dynamisys.co.uk/ForumsBlogs/Blogs/tabid/300/EntryId/73/To-IBM-for-C.aspx</guid>
      <pubDate>Thu, 22 May 2008 00:00:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.net-programmer.co.uk/DesktopModules/Blog/Trackback.aspx?id=73</trackback:ping>
    </item>
  </channel>
</rss>