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: 27-Oct-2005 01:18
In your example you can populate a dropdown by using an Enum, which is fine if the values always stay the same. The problem I have is that the values that I want to add into the dropdown list will be taken from my DB.

Could you please give me an example (in vb.net if possible) of how to do this as I am unsure.

Thank you in advance

Simon
Link Posted: 28-Oct-2005 02:58
If you mention about DynamicallyAutoDetectDataTypeColumn,
this functionality is result of using Reflection - this column type gets TypeEditor for current data and receives all necessary data from TypeEditor.
If you want to fetch data from DB you can use LookupListColumn to populate data for dropdown list.
Link Posted: 01-Nov-2005 01:31
I am still unsure of how to do this as I am quite new to VB.Net. Do you have an example of how this works in you flygrid examples???

Also I meant that my values that I wanted to appear in the dropdown would be from an arraylist NOT my DB. I am using the DynamicallyAutoDetectDataTypeColumn column type.

Any help you could give me would be appreshiated, sorry for being a pain.

Thanks

Simon
Link Posted: 01-Nov-2005 05:33
Here is a simple example that show how to implement custom dropdown list:
[VB.Net]
Public Class DynamicallyDropdownColumn
  Inherits Column
  Public Sub New(ByVal caption As String)
     MyBase.New(caption)
     EditorStyle = EditorStyle.DropDown
  End Sub
  
  Public Overrides Function GetValueList(ByVal node As NodeBase) As Object()
    'here you can return value list for dropdown
    Return New String() {"One", "Two", "Three"}
  End Function
End Class


Also you can see the code of CustomDropdownColumn in the VB.Net demo (customStylesGridForm.vb sample)
Link Posted: 01-Nov-2005 10:29
Thank you for the code example, I have added it to my app. but I am still having a slight problem as it throws up an error.

'An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll

Additional information: Key cannot be null.'

I am obviously doing something wrong.  

The code I am using is:


Dim test As DynamicallyDropdownColumn
data = New Object() {attCode, attDesc, attIso, attPipe, attName, test}
Me.lstNameProp.Rows.Items.Add(New Node(data))


If you could please help me out that would be great.

Thank you

Simon

P.S. Thank you so much for all your help with my large amount of posts.
Link Posted: 02-Nov-2005 04:46
I've made a small VB test project to demonstrate DynamicallyDropDownColumn, please download this project  here and test.
Do not forget to refresh references to the FlyGrid assemblies in this project before build or open form designer.
Link Posted: 03-Nov-2005 13:36
Thank you for the project it is the kind of thing that I want, however in your example project you are creating a new column, where I would like to add it to an all ready defined (at design time) DynamicallyAutoDetectDataTypeColumn column.

So I basically have a the same situation to your vertical grid example project,  but I would like to add the custom dropdown that you have done to that.

Thank you so much for your patience

Simon
Link Posted: 03-Nov-2005 13:48
DynamicallyAutoDetectDataTypeColumn dinamically detect which type of editor can be used on editing certain cell.
DynamicallyAutoDetectDataTypeColumn extracts type of data in the cell and extracts UITypeEditor instance for this type.
UITypeEditor helps to provide list of values or use dialog editor (elllipsis button) editor for editing current cell.
See the VB.Net code (Vertical Grid) - you'll find custom type FileNameBasedData and attached to this class attribute [Editor....]
See the FileNameBasedData.FileNameBasedDataEditor code to understand how to provide values list for some data type this its  UITypeEditor.
Hope that my explanations help you to solve your problem.
Link Posted: 09-Nov-2005 10:19
Sorry to bother you again but I am getting a bit frustrated with this now. I have searched the net, and I have managed to get the following code (this is edited from your example in vertical grid demo), but when I click on the field it displays the dropdown arrow but does not display a dropdown control like I would expect. I am obviously doing something wrong....... as always.

If you could help me (even more than you have) I would appreshiate it.


     _
    Public Class FileNameBasedData
        Public Class FileNameBasedDataEditor
            Inherits System.Drawing.Design.UITypeEditor
            Public Sub New()
                MyBase.New()
            End Sub

            Public Overloads Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
                Return UITypeEditorEditStyle.DropDown
            End Function

            Public Overloads Overrides Function EditValue(ByVal context As ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As Object) As Object
                Dim _fileNameBasedData As FileNameBasedData = CType(value, frmControl.FileNameBasedData)
                If (Not _fileNameBasedData Is Nothing) Then
                    Dim _openFileDialog As New DropDownListColumn
                    _openFileDialog.Items.Add("hello")
                    _openFileDialog.Items.Add("hello1")
                    _openFileDialog.Items.Add("hello2")

                    Return _fileNameBasedData
                End If
                Return MyBase.EditValue(context, provider, value)
            End Function
        End Class
        Private _fileName As String
        Private Shared _defaultDirectory As String
        Shared Sub New()
            _defaultDirectory = String.Empty
        End Sub
        Public Sub New()
            _fileName = String.Empty
        End Sub
        Public Sub New(ByVal fileName As String)
            Me._fileName = fileName
        End Sub
        Public Shared Property DefaultDirectory() As String
            Get
                Return _defaultDirectory
            End Get
            Set(ByVal Value As String)
                _defaultDirectory = Value
            End Set
        End Property
        Public Overridable Property FileName() As String
            Get
                Return Me._fileName
            End Get
            Set(ByVal Value As String)
                If (_fileName  Value) Then
                    Me._fileName = Value
                End If
            End Set
        End Property
        Public Overridable ReadOnly Property IsEmpty() As Boolean
            Get
                Return Not (_fileName Is Nothing Or _fileName = String.Empty)
            End Get
        End Property
        Public Overrides Function ToString() As String
            Return IIf((Not Me.FileName Is Nothing), _fileName, String.Empty)
        End Function
    End Class


Thank you so much

Simon
Link Posted: 09-Nov-2005 16:58
FileNameBasedData has editor that provides editing in modal dialog,
You need Dropdown style.
In this case you can provide TypeConverter (see the MSDN for the TypeConverterAttribute) for your data type.

_
Public Class Class1
    ' Insert code here.
End Class 'MyClass


In the MyClassConverter (inherited from TypeConverter) you should override
GetStandardValues, GetStandardValuesExclusive methods to provde data for dropdown list box. See the MSDN for examples.