/// <summary>
        /// Initializes a new instance of the <see cref="ColumnDomainConverter"/> class.
        /// </summary>
        /// <param name="ds">The database holding domain data</param>
        /// <param name="cd">The column domain that is being converted (not null)</param>
        public ColumnDomainConverter(IDataServer ds, IColumnDomain cd)
        {
            if (ds == null || cd == null)
            {
                throw new ArgumentNullException();
            }

            m_DataServer   = ds;
            m_ColumnDomain = cd;
            IDomainTable dt = cd.Domain;

            string[] lookups = dt.GetLookupValues(ds.ConnectionString);
            m_Values = new StandardValuesCollection(lookups);
        }
        private void grid_SelectionChanged(object sender, EventArgs e)
        {
            domainGrid.Tag = null;
            domainGrid.Rows.Clear();
            domainGrid.Enabled = false;

            if (!grid.Enabled)
            {
                return;
            }

            DataGridViewRow row = GetSelectedGridRow();

            if (row == null)
            {
                return;
            }

            // Show the data type
            DataColumn dc = (DataColumn)row.Tag;

            dataTypeLabel.Text = dc.DataType.Name;

            if (!dc.AllowDBNull)
            {
                dataTypeLabel.Text += " not null";
            }

            if (dc.DataType == typeof(string))
            {
                if (dc.MaxLength == 1)
                {
                    dataTypeLabel.Text += " (1 character)";
                }
                else
                {
                    dataTypeLabel.Text += String.Format(" (up to {0} characters)", dc.MaxLength);
                }
            }

            // Show any domain values
            IColumnDomain cd = FindColumnDomain(dc.ColumnName);

            domainValuesLabel.Enabled = (cd != null);

            if (cd != null)
            {
                // Note the currently defined value
                string           currentValue = row.Cells["dgcValue"].FormattedValue.ToString();
                DataGridViewCell currentCell  = null;

                IDomainTable domainTable = cd.Domain;
                string[]     lookups     = domainTable.GetLookupValues(m_DataServer.ConnectionString);
                domainGrid.RowCount = lookups.Length;
                for (int i = 0; i < lookups.Length; i++)
                {
                    string          shortValue = lookups[i];
                    DataGridViewRow r          = domainGrid.Rows[i];
                    r.Tag = shortValue;
                    r.Cells["dgcShortValue"].Value = shortValue;
                    r.Cells["dgcLongValue"].Value  = domainTable.Lookup(m_DataServer.ConnectionString, shortValue);

                    // If we have just defined the current data value, remember the cell so
                    // that we can set it once the grid has been loaded.
                    if (shortValue == currentValue)
                    {
                        currentCell = r.Cells["dgcShortValue"];
                    }
                }

                domainGrid.CurrentCell = currentCell;
                domainGrid.Enabled     = true;
                domainGrid.Tag         = domainTable;
            }
        }