Site Search:
Sign in | Join | Help

This Blog

Syndication

Tags

No tags have been created or used yet.

Janus System

All things for all Janus products

June 2007 - Posts

  • Dynamic dropdowns in a gridex control

    Getting multiple dropdown controls to work with dynamic data is not for the faint of heart.  Hopefully this will help give others a head start.

     Create a gridex control and add 2 dropdown lists as per janus tutorials. 

    In the load event of the form, add:

    'load the grid classification dropdown
    'In this case the dropdown has 2 columns, the classification name and the database row id
    grdPeople.DropDowns(0).DataSource = Classification.getDataSet().Tables(0)

    'This dropdown has 3 columns, sub class name, database row id, and the classification foreign key
    grdPeople.DropDowns(1).DataSource = Classification.getSubClassDataSet().Tables(0)

    'There is no selection changed event for the dropdowns.
    'You have to use the dropdown hide event of the grid instead.
    'It will fire for any dropdown on the grid so you have to check for which one did
    AddHandler grdPeople.DropDownHide, AddressOf loadSubClassDDL

    'Because the dropdowns are the same instance for each row, you can't reload the dataset for each row
    'You need to apply a filter instead.  The second dropdown needs to have all possible selection choices
    'preloaded into it.

    'In this case for the inital load of the form I'm only going to show the sub classes with a foreign key of 1

    'apply the default for the empty document
    Dim filter As New GridEXFilterCondition
    filter.Column = grdPeople.DropDowns(1).Columns("intClassificationIDFK")
    filter.ConditionOperator = ConditionOperator.Equal
    filter.Value1 = 1  'The default foreign key for an empty document
    grdPeople.DropDowns(1).ApplyFilter(filter)



    In the loadSubClassDDL function (referenced in the addhandler call above) add:

    'Check the column to make sure that its the first column that fired the event
    If e.Column.DataMember = "vchrClassificationName" Then

        'Each row uses the same dropdown, so changing the dataset isnt practical
        'filtering the data instead
        Dim filter As New GridEXFilterCondition
        filter.Column = grdPeople.DropDowns(1).Columns("intClassificationIDFK")
        filter.ConditionOperator = ConditionOperator.Equal
        filter.Value1 = grdPeople.DropDowns(0).GetValue(1).ToString()
        grdPeople.DropDowns(1).ApplyFilter(filter)
    End If


    The grids SelectionChanged event will also need to be trapped.  Otherwise when someone clicks another row in the
    grid it will leave the filtering as it was the last time the first dropdown was changed (in any row).

    In this case I'm setting the filter through a lookup table.  I did it this way because this event is fired before the id in
    the first dropdown list is updated.  The text in the cell itself is correct though.

    If grdPeople.SelectedItems(0).RowType = RowType.Record Then
        'when a user changes which row is selected the filter needs to be changed to
        'match the current rows classification
        Dim filter As New GridEXFilterCondition
        filter.Column = grdPeople.DropDowns(1).Columns("intClassificationIDFK")
        filter.ConditionOperator = ConditionOperator.Equal
        filter.Value1 = cls.lookupID(grdPeople.GetValue("vchrClassificationName").ToString())
        'filter.Value1 = grdPeople.DropDowns(0).GetValue(1).ToString()
        grdPeople.DropDowns(1).ApplyFilter(filter)
    End If


  • Canceling a GridEx addingRecord event

    The best way to cancel an addingrecord event in the gridex control that I've found is to call the cancelCurrentEdit() function.  I was initially setting the e.cancel property to true, but that had the side effect of not letting me change the focus from that row in the grid :)

     If isGoodRow = False Then
                grdPeople.CancelCurrentEdit()
    Else
                insert the new row into the database, etc.
    End If

  • GridEX with a CalendarCombo

    Here is a clever way to use the standalone calendarcombo inside the grid.  This gets around the problem of editing the date and time as text.  This is based off of code i found on the Janus forums posted by "Stage Presence"

    Private Sub grid_InitCustomEdit(ByVal sender As Object, ByVal e As Janus.Windows.GridEX.InitCustomEditEventArgs) Handles grid.InitCustomEdit
            Dim cc As New Janus.Windows.CalendarCombo.CalendarCombo
            cc.DateFormat = Janus.Windows.CalendarCombo.DateFormat.DateTime
            cc.BorderStyle = Janus.Windows.CalendarCombo.BorderStyle.None
            cc.VisualStyle = Janus.Windows.CalendarCombo.VisualStyle.Standard
            cc.ShowDropDown = True
            cc.ShowUpDown = False
            cc.UseCompatibleTextRendering = False
            cc.Value = CType(e.Value, DateTime)
            e.EditControl = cc
        End Sub

        Private Sub grid_EndCustomEdit(ByVal sender As Object, ByVal e As Janus.Windows.GridEX.EndCustomEditEventArgs) Handles grid.EndCustomEdit

            Dim cc As Janus.Windows.CalendarCombo.CalendarCombo = CType(e.EditControl, Janus.Windows.CalendarCombo.CalendarCombo)
            e.Value = cc.Value
        End Sub

     Then set the column edit type to custom.

More Posts Next page »