private void lbConflictResolutionColumns_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                int indexFromPoint = lbConflictResolutionColumns.IndexFromPoint(e.Location);

                if (indexFromPoint != -1)
                {
                    var RightClickMenu = new ContextMenuStrip();

                    IResolveDuplication resolver =
                        (IResolveDuplication)lbConflictResolutionColumns.Items[indexFromPoint];

                    string target    = resolver.DuplicateRecordResolutionIsAscending ? "DESC" : "ASC";
                    string currently = resolver.DuplicateRecordResolutionIsAscending ? "ASC" : "DESC";

                    RightClickMenu.Items.Add(
                        "Set " + resolver.GetRuntimeName() + " to " + target + " (Currently resolution order is " +
                        currently + ")", null, delegate
                    {
                        //flip its bit
                        resolver.DuplicateRecordResolutionIsAscending =
                            !resolver.DuplicateRecordResolutionIsAscending;
                        //save it to database
                        resolver.SaveToDatabase();
                        //refresh UI
                        RefreshUIFromDatabase();
                    });

                    RightClickMenu.Show(lbConflictResolutionColumns.PointToScreen(e.Location));
                }
            }
        }
        private string AppendRelevantOrderBySql(string sql, IResolveDuplication col)
        {
            string colname = _querySyntaxHelper.EnsureWrapped(col.GetRuntimeName(LoadStage.AdjustRaw));

            string direction = col.DuplicateRecordResolutionIsAscending ? " ASC" : " DESC";

            //dont bother adding these because they are hic generated
            if (SpecialFieldNames.IsHicPrefixed(colname))
            {
                return(sql);
            }

            ValueType valueType = GetDataType(col.Data_type);

            if (valueType == ValueType.CharacterString)
            {
                //character strings are compared first by LENGTH (to prefer longer data)
                //then by alphabetical comparison to prefer things towards the start of the alphabet (because this makes sense?!)
                return
                    (sql +
                     "LEN(ISNULL(" + colname + "," + GetNullSubstituteForComparisonsWithDataType(col.Data_type, true) + "))" + direction + "," + Environment.NewLine +
                     "ISNULL(" + colname + "," + GetNullSubstituteForComparisonsWithDataType(col.Data_type, true) + ")" + direction + "," + Environment.NewLine);
            }

            return(sql + "ISNULL(" + colname + "," + GetNullSubstituteForComparisonsWithDataType(col.Data_type, true) + ")" + direction + "," + Environment.NewLine);
        }