NPaletteColorPane - is it possible to reorder colours by drag and drop?


https://www.nevron.com/Forum/Topic7350.aspx
Print Topic | Close Window

By Kevin Harrison - 11 Years Ago

I need to select a series of colours and then have the ability to delete or reorder the selected colours (preferably with multi-selection).

Currently I am using an NPaletteColorPane to show the available colours.

Selected colours are displayed in a single column DataGridView, which allows me to reorder single or multiple selections by drag and drop or by adding Up/Down buttons etc. However, this looks messy, particularly when the scroll bar appears.

What would be really cool is to use a second NPaletteColorPane (or similar control) which allows me to reorder the colours. I can see how to achieve this using Up/Down buttons, but only for single selections. Is drag/drop possible here?

.. or do have a better suggestion to achieve what I want?

Thanks

Kevin

By Nevron Support - 11 Years Ago
Hello Kevin,

You can override ProcessDialogKey to handle possible key sequence which can move the colors up and down.

Here is one example implementation:

public class MyNPaletteColorPane : NPaletteColorPane
   {
      protected override bool ProcessDialogKey(Keys keyData)
      {
         if(!Selectable)
            return base.ProcessDialogKey (keyData);

         int currIndex = SelectedIndex;

         switch(keyData)
         {               
            case Keys.Control | Keys.Up:
               currIndex--;               
               if (currIndex < 0 )
               {
                  currIndex = ColorPalette.Entries.Length - 1;
               }               
               break;
            case Keys.Control | Keys.Down:
               currIndex++;               
               if (currIndex > ColorPalette.Entries.Length - 1)
               {
                  currIndex = 0;
               }               
               break;
            default:
               return base.ProcessDialogKey(keyData);               
         }
                  
         NArgbColorValue c = ColorPalette.Entries[SelectedIndex];
         NArgbColorValue c1 = ColorPalette.Entries[currIndex];
         ColorPalette.Entries[SelectedIndex] = c1;
         ColorPalette.Entries[currIndex] = c;
         PopulateColors();
         SelectedIndex = currIndex;

         if (ChangeStyle == ColorChangeStyle.OnMouseUp)
         {
            OnColorChanged(EventArgs.Empty);
         }

         return true;
      }
   }

Unfortunately, control doesn't allow a multiple selection.