Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Populate dropdown list.....

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

Populate dropdown list.....
Link Posted: 10-Nov-2005 02:54
See the code (sorry, c#) to understand how to provide dropdown value list for your data type (for LocalizationCulture property):
[c#]
  public class LocalizationInfo : Component
  {
    //This is a type converter that provides list of values for editing in the
    //PropertyGrid and in the DynamicallyAutoDetectDataTypeColumn
    public class CultureInfoConverter : TypeConverter
    {
      private static Hashtable cultures;
      public static CultureInfo GetCulture(string displayName)
      {
        if (cultures == null)
        {
          InitCultures();
        }
        return cultures[displayName] as CultureInfo;
      }
      
      private static void InitCultures()
      {
        cultures = new Hashtable();
        foreach(CultureInfo ci in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.InstalledWin32Cultures))
        {
          cultures[ci.DisplayName] = ci;
        }
      }
      public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
      {
        return true;
      }
      public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
      {
        return true;
      }
      public override bool IsValid(ITypeDescriptorContext context, object value)
      {
        if(value is string)
        {
          if (cultures == null)
          {
            InitCultures();
          }
          if (cultures != null)
          {
            return cultures.Contains(value);
          }
          return false;
        }
        return base.IsValid (context, value);
      }

      public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
      {
        if (cultures == null)
        {
          InitCultures();
        }
        if (cultures != null)
        {
          System.ComponentModel.TypeConverter.StandardValuesCollection svc = new System.ComponentModel.TypeConverter.StandardValuesCollection(cultures.Keys);
          return svc;
        }
        return base.GetStandardValues (context);
      }
    }

    
    private FileName fileName = new FileName(string.Empty);
    private CultureInfo culture = System.Globalization.CultureInfo.InvariantCulture;
    [Editor(typeof(NineRays.ILOMD.Options.Design.LocalizationFileEditor), typeof(System.Drawing.Design.UITypeEditor))]
    public FileName LocalizationFile
    {
      get { return fileName;}
      set
      {
        if (value != fileName)
        {
          fileName = value;
          OnChanged();
        }
      }
    }

    public bool ShouldSerializeLocalizationFile()
    {
      return fileName != null && fileName.Name != null && fileName.Name != string.Empty;
    }

    [TypeConverter(typeof(LocalizationInfo.CultureInfoConverter))]
    public string LocalizationCulture
    {
      get { return culture.DisplayName;}
      set
      {
        if (value != LocalizationCulture)
        {            
          CultureInfo ci = CultureInfoConverter.GetCulture(value);
          if (ci != null)
          {
            culture = ci;
            OnChanged();
          }
        }
      }
    }
        
    public bool ShouldSerializeLocalizationCulture()
    {
      return culture != null && culture != CultureInfo.InvariantCulture;
    }
    internal EventHandler Changed;
    private void OnChanged()
    {
      if (Changed != null)
        Changed(this, EventArgs.Empty);
    }
  }
Link Posted: 13-Nov-2005 07:30
I have tried using the example from customStylesGridForm, but for some reason it does not seem to produce the dropdown flygrid as it does in your example. I have posted the code below, and I am obviously doing something wrong.


     _
        Public Class CustomDropdownColumn
        Inherits Column
        Implements ISupportsCustomDropDown

        Private _dropdownGrid As FlyGrid
        Private lookupData As Object()
        Private editedNode As NodeBase
        Private dds As IDropDownService

        Public Sub New(ByVal caption As String, ByVal lookupData As Object())
            MyBase.New(caption)
            _dropdownGrid = Nothing
            editedNode = Nothing
            dds = Nothing
            Me.lookupData = lookupData
        End Sub

        Friend ReadOnly Property DropdownGrid() As FlyGrid
            Get
                If (_dropdownGrid Is Nothing) Then
                    _dropdownGrid = CreateDropdownGrid()
                End If
                Return _dropdownGrid
            End Get
        End Property
        Protected Overrides Sub OnChanged(ByVal mode As NineRays.Windows.Forms.Grids.InvalidationMode, ByVal refreshMap As Boolean)
            MyBase.OnChanged(mode, refreshMap)
            If (Me.Current) Then
                Me.BackColor = Color.AntiqueWhite
            Else
                Me.BackColor = SystemColors.Control
            End If
        End Sub
        Public Overrides Property EditorStyle() As EditorStyle
            Get
                Return EditorStyle.DropDownResizable
            End Get
            Set(ByVal Value As EditorStyle)
            End Set
        End Property

        Private Function CreateDropdownGrid() As FlyGrid
            Dim grid As FlyGrid = New FlyGrid
            Dim first As Column = New Column("User Name")
            first.FitMode = ColumnFitMode.FitToText
            Dim second As Column = New Column("Description")
            second.FitMode = ColumnFitMode.FitToText
            grid.Columns.Items.AddRange(New Column() {first, second})
            grid.Options = grid.Options Or (GridOptions.RowSelect Or GridOptions.[ReadOnly] Or GridOptions.ShowFocusRectangle)
            grid.Rows.DataSource = lookupData
            grid.BackColor = SystemColors.Window
            Dim width As Integer = 0
            For i As Integer = 0 To grid.Columns.Items.Count - 1
                width += grid.Columns.Items(i).Width + 2
            Next i
            Dim height As Integer = (grid.Columns.HeadersHeight + 1) + (grid.Rows.Items.Count * (grid.Rows.DefaultRowHeight + 1))
            grid.Size = New Size(width, height)
            AddHandler grid.KeyDown, AddressOf Me.grid_KeyDown
            AddHandler grid.NodeDblClick, AddressOf Me.grid_NodeDblClick
            Return grid
        End Function

        Private Sub SetSelection(ByVal data As String)
            If (Not lookupData Is Nothing) Then
                For i As Integer = 0 To lookupData.Length - 1
                    Dim row As System.String() = CType(lookupData(i), System.String())
                    Dim cell As String = row(0)
                    If (cell = data) Then
                        DropdownGrid.Selected = DropdownGrid.Rows.GetNodeFromRow(i)
                        Exit For
                    End If
                Next i
            End If
        End Sub

        Public Overridable Sub EditInDropDown(ByVal provider As IServiceProvider, ByVal node As NodeBase) Implements ISupportsCustomDropDown.EditInDropDown
            dds = CType(provider.GetService(GetType(IDropDownService)), IDropDownService)
            Dim grid As FlyGrid = CType(provider, FlyGrid)
            If Not grid Is Nothing Then
                DropdownGrid.Style = grid.Style
                DropdownGrid.Stylist = grid.Stylist
            End If
            If Not dds Is Nothing Then
                editedNode = node
                SetSelection(MyBase.GetTextValue(node))
                dds.DropDownControl(DropdownGrid, Me, True)
                If (Not editedNode Is Nothing) AndAlso (Not DropdownGrid.Selected Is Nothing) Then
                    MyBase.SetValue(editedNode, DropdownGrid.Selected.GetCellValue(0))
                End If
            End If
        End Sub

        Private Sub grid_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
            If (e.KeyCode = Keys.[Return]) OrElse (e.KeyCode = Keys.Escape) Then
                If e.KeyCode = Keys.Escape Then
                    editedNode = Nothing
                End If
                dds.CloseDropDown()
            End If
        End Sub

        Private Sub grid_NodeDblClick(ByVal sender As Object, ByVal node As NodeBase, ByVal col As Column)
            dds.CloseDropDown()
        End Sub
    End Class


And this is the code on how I am trying to load the dropdown.

The attCode, attDesc, attIso, attPipe, attName are all just string values.


data = New Object() {attCode, attDesc, attIso, attPipe, attName, lookupData(1)(0)}
Me.FlyGrid1.Rows.Items.Add(New Node(data))


Once again thanks for your time and patience.

Simon
Link Posted: 13-Nov-2005 23:22
Sorry I forgot to say that it does not produce a dropdown on a DynamicallyAutoDetectDataTypeColumn column type