Home - Forums-.NET - FlyGrid.Net (Windows Forms) - How do I find which flygrid has caused the event

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

How do I find which flygrid has caused the event
Link Posted: 30-May-2006 01:26
Hello!!

I use DynamicallyAutoDetectDataTypeColumn and have three flygrids in
one win form.

In some column in each of the three flygrids I have dropdown list
boxes where I use some of your example code with improvedString class.
In my code I have moved important code existing in improvedstring
class into the string class.
So I don't use the Improvedstring class any more but the
functionallity is the same.

When I click and select one item from the the dropdown list box no matter which of the three flygrid it is method GetEditStyle is called and
EditValue is also called. These two exist in StringClass in my code.


Now to my question is it possible to find out in which flygrid I made
a selection in the dropdown flygrid ?

So when I made a selection in the drop down list box in one of the
three flygrids I just want to
know which flygrid I know handling.

Hope you understand what I mean.

//Tony
Link Posted: 30-May-2006 02:03
If you handle NodeBase you can easily determine owner:
[c#]
FlyGrid flyGrid = node.Owner.FlyGrid;
Link Posted: 30-May-2006 02:54
Hello!

This is the stringclass much the same as the string class you have in your
example.

The method EditValue is used for dropdown the list box for a cell.
When this EditValue is called is it possible to find the name of flygrid where
the dropdown list occurred.

For example if you have a flygrid called myflygrid and in this flygrid you have some cells that have drop down list box.
So when you click on the dropdown list box symbol this EditValue is
called and in this method I hope to be able to find that is was flygrid name myflygrid you clicked in.

Here is the complete StringClass
This public class StringClassEditor : UITypeEditor
      {
         private IWindowsFormsEditorService wse = null;
         private StringClass editedSc           = null;
         private string originalValue           = null;

         private bool StringClassHasValueList(StringClass sc)
         {
            return sc != null && sc.ValuesList.Count > 0;
         }

         ///
         /// Set drop down style
         ///
         public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
         {
            return System.Drawing.Design.UITypeEditorEditStyle.DropDown;
         }

         ///
         /// Handle the actual editing and drop down the list box
         ///
         public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
         {      
            //Type type = value.GetType();  
            
            if (StringClassHasValueList(value as StringClass))
            {  
               wse = (IWindowsFormsEditorService ) (provider.GetService(typeof(IWindowsFormsEditorService)));
            
               if (wse != null)
               {
                  ListBox lb = new ListBox();
                  editedSc = (StringClass)value;
                  originalValue = editedSc.StrValue; // get property strValue from StringClass
                  //copy all item from ArrayList to a new string[] array
                  string[] values = (string []) (editedSc.ValuesList.ToArray(typeof(string)));
            
                  // check drop down list box size
                  if (values.Length == 1)
                     lb.Size = lb.Size = new System.Drawing.Size(1,values.Length*10/2 + values.Length*10+15);
                  else if (values.Length < 7)
                     lb.Size = lb.Size = new System.Drawing.Size(1,values.Length*10/2 + values.Length*10);

                  lb.Items.AddRange(values);
                  // get property Value get strValue from StringClass
                  int selectedIndex = editedSc.StrValue != null ? lb.Items.IndexOf(editedSc.StrValue) : -1;
                  if (selectedIndex != -1)
                     lb.SelectedIndex = selectedIndex;
                             
                  //lb.KeyDown              += new KeyEventHandler(ListBox_KeyDown);
                  lb.SelectedIndexChanged += new EventHandler(ListBox_SelectedIndexChanged);
                  //lb.Click                += new EventHandler(ListBox_Click);
                  
                  wse.DropDownControl(lb);
                  wse = null;
                  return editedSc; // return a StringClass object
               }
            }
            return base.EditValue (context, provider, value);
         } // end EditValue

        

         ///
         /// Event handler when the index in drop down list box has changed
         ///
         private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
         {
            wse.CloseDropDown();
            ListBox listBox = sender as ListBox;
            editedSc.StrValue = (string)listBox.SelectedItem; // get item
         }
      } // end StringClassEditor
   } // end StringClass

//Tony
Link Posted: 30-May-2006 03:41

The method EditValue is used for dropdown the list box for a cell.
When this EditValue is called is it possible to find the name of flygrid where
the dropdown list occurred.


Yes, you can extract FlyGrid instance from provider parameter provided by EditValue:
[c#]
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
  FlyGrid flyGrid = provider as FlyGrid;
  //....
}