Help needed

Posted by: Donald.l.bradley on 22 October 2018, 9:27 am EST

    • Post Options:
    • Link

    Posted 22 October 2018, 9:27 am EST

    I am creating a WinForm app using VB. I have added a flex grid to my solution and connected to a SQL Server table as the data source. I want to change the columns(fields) to dynamic drop downs not list. How can I have the drop down connect to another table on the server for valid values/

    Thanks in advance

    Don

  • Posted 22 October 2018, 3:43 pm EST

    Hi Don,

    You can use a ComboBox as Editor of a column and set the table as DataSource of the ComboBox. Also, if you have a table with key-value pairs (for eg. EmployeeID, EmployeeName) and you want to display the value (EmployeeName), you would need to use DataMap property of the column so that initial values of the grid are also mapped correctly.

    Here’s an example of a simple ComboBox editor:

    Dim comboEmployee = New ComboBox()
    comboEmployee.DataSource = GetDataTable("select EmployeeID from Employees")
    comboEmployee.DisplayMember = "EmployeeID"
    
    C1FlexGrid1.Cols("EmployeeID").Editor = comboEmployee
    

    For a ComboBox with mapped values, you can do something like this:

    Dim comboCustomer = New ComboBox()
    Dim customerTable = GetDataTable("select CustomerID, CompanyName from Customers")
    comboCustomer.DataSource = customerTable
    comboCustomer.DisplayMember = "CompanyName"
    comboCustomer.ValueMember = "CompanyName"
    C1FlexGrid1.Cols("CustomerID").Editor = comboCustomer
    
    Dim dictionary = New Dictionary(Of String, String)()
    For row = 0 To customerTable.Rows.Count - 1
        dictionary.Add(customerTable(row)("CustomerID"), customerTable(row)("CompanyName"))
    Next
    C1FlexGrid1.Cols("CustomerID").DataMap = dictionary
    

    Please refer to the attached sample to see an example of both methods.

    Regards,

    Jitender

    DynamicDropdown.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels