Main Menu
Knowledge Base
Product Registration
Log an Incident
Request a Feature
Search Incidents/Bug Reports


Search KB

Please note: In an effort to better serve you, we are in the process of restructuring DevCenter. In the process, we have moved many items that you may be used to finding in DevCenter over to the Main Site. If you are having trouble locating something, please try looking at the following places:

Knowledge Base Article: KB04878

HOWTO:How can I change the drop down list on a cell by cell basis in UltraWinGrid


The information in this article applies to:
UltraWinGrid (v3.1.20041, 3.2.20042, 4.3.20043, 5.1.20051, 5.2.20052, 5.3.20053)
  Article Created: 
2/4/2004

Last Updated:
11/29/2005

Article Type
How To
  
Page Options
Average Rating:
4 out of 10

Rate this page
Print this page
E-mail this page
Add to Favorites

Summary

Prior to the release of the WinGrid v3 in NetAdvantage 2003 Volume 3, the value list and editor control references were only on the UlraGridColumn object. With the release of the WinGrid v3 these properties were moved down to the UltraGridCell level. With this change, the process to display different UltraCombos on a cell-by-cell basis in a column became more simplified.

Additional Information

When the WinGrid is drawing to screen, columns that have an UltraCombo type editor use the UltraCombo’s DisplayMember to display the proper text in the cell. If the value of the cell is not found in the UltraCombo, the UltraWinGrid should show the value of the cell in an unformatted way.

For example, in the case of an UltraCombo populated with the names of states, if the value “NY” is not found, then the cell will show “NY”. However this can become problematic if the ColumnType is a DropDownList, as this value is clearly not in the value list.

Due to this behavior, simply switching the DataSource of the UltraCombo will cause the other rows in the column that share the UltraCombo as an editor to flicker display between showing the value of the column, when the value is not found in the current UltraCombo, or the desired DisplayMember text, when the value can be paired up.

The correct way to use a dynamic UltraCombo as a cell editor is to use two UltraCombo controls: one UltraCombo to act as a global source and a second to act as a cell editor.

Step-By-Step Example

To accomplish the goal of having the UltraCombo vary based on the value of another cell, set an UltraCombo to be the editor on the UltraGridColumn object. This UltraCombo should contain all the possible value member and display member pairs.

In C#:

//Assign State UltraCombo to State Column
e.Layout.Bands[0].Columns["State"].ValueList = this.ucStateMaster;
e.Layout.Bands[0].Columns["State"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;

In VB.NET:

'Assign State UltraCombo to State Column
With e.Layout.Bands(0).Columns("State")
    .ValueList = Me.ucStateMaster
    .Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate
End With

Since this UltraCombo will be used as the editor for all cells in the column that don’t have an editor explicitly tied to the cell, this will allow the cells to always show the correct display text in the cell as opposed to the value of the cell.

In the BeforeEnterEditMode of the cell that will have the dynamic UltraCombo, switch the datasource on the UltraCombo to be the DataSource for that particular cell. Then set the editor on the cell to be the second, more specific UltraCombo.

In C#:

private void ultraGrid1_BeforeEnterEditMode(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (this.ultraGrid1.ActiveCell.Column.Key == "State") // ensure that we swap in the correct states
    {
        if (this.ultraGrid1.ActiveCell.Row.Cells["Region"].Value != null)
        {
            DataTable dt = BuildStateList();
            dt.DefaultView.RowFilter = "Region = \'" + this.ultraGrid1.ActiveCell.Row.Cells["Region"].Value + "\'";
            this.ucState.DataSource = dt;
            this.ucState.DisplayMember = "Name";
            this.ucState.ValueMember = "Code";
            this.ucState.DisplayLayout.Bands[0].Columns["Region"].Hidden = true;
            this.ultraGrid1.ActiveCell.ValueList = this.ucState;
        }
    }
}

In VB.NET:

Private Sub UltraGrid1_BeforeEnterEditMode(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles UltraGrid1.BeforeEnterEditMode
        If Me.UltraGrid1.ActiveCell.Column.Key = "State" Then ' ensure that we swap in the correct states
            If Not Me.UltraGrid1.ActiveCell.Row.Cells("Region").Value Is Nothing Then
                Dim dt As DataTable = BuildStateList()
                dt.DefaultView.RowFilter = "Region = '" & Me.UltraGrid1.ActiveCell.Row.Cells("Region").Value & "'"
                Me.ucState.DataSource = dt
                Me.ucState.DisplayMember = "Name"
                Me.ucState.ValueMember = "Code"
                Me.ucState.DisplayLayout.Bands(0).Columns("Region").Hidden = True
                Me.UltraGrid1.ActiveCell.ValueList = Me.ucState
            End If
        End If
    End Sub

Finally, in the BeforeCellDeactivate, set the ValueList of the cell to Nothing (or null in C#). This will allow the cell to use the column's ValueList as its source.

In C#:

private void ultraGrid1_BeforeCellDeactivate(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (this.ultraGrid1.ActiveCell.Column.Key == "State") // ensure that we swap in the correct states
    {
        this.ultraGrid1.ActiveCell.ValueList = null;
    }
}

In VB.NET:

    Private Sub UltraGrid1_BeforeCellDeactivate(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles UltraGrid1.BeforeCellDeactivate
        If Me.UltraGrid1.ActiveCell.Column.Key = "State" Then ' ensure that we swap in the correct states
            Me.UltraGrid1.ActiveCell.ValueList = Nothing
        End If
    End Sub

Samples

wingrid_using_cell_based_combo_vb.zip
 VB.Net sample showing how to use two UltraCombos in the V3 UltraWinGrid to see differnt drop downs on a cell by cell basis


wingrid_using_cell_based_combo_cs.zip
 C# sample showing how to use two UltraCombos in the 5.2 WinGrid to see different drop downs on a cell by cell basis



How would you rate the quality of this content?
Poor -----------------------------------------> Outstanding

Tell us why you rated the content this way. (optional)