質問

I have a column of type dropdown, which is created inside a Ultragrid. Now I have to add some static values for the column.

//Code

    UltraGridColumn = workflowGrid.Rows.Band.Columns("ShowTransactionId")
    UltraGridColumn.Header.Caption = "Show TransactionId"
    UltraGridColumn.Hidden = False
    UltraGridColumn.Style = UltraWinGrid.ColumnStyle.DropDownList
    UltraGridColumn.ValueList = 'Code here

Here I have to add Yes/No inside the column. How can I do that?

役に立ちましたか?

解決

It is a common requirement of mine. I have a internal utility method that build this kind of valuelist on the fly. Here I use a boolean value of true for the YES string and a boolean false for NO string, but, of course, you should change these values depending on the real value for the datasource column

    Public Shared Function YesNoValueList() As Infragistics.Win.ValueList
        Dim vlYN = new Infragistics.Win.ValueList()
        vlYN.ValueListItems.Add(false, "NO")
        vlYN.ValueListItems.Add(true, "YES")
        vlYN.Key = "_YES_NO_"
        return vlYN
    End Sub

    ....

    UltraGridColumn.ValueList = InfragisticsHelper.YesNoValueList()

EDIT Obviously this ValueList is of little consequence on the performance of your program and thus you could call this method every time you need it, but if you really want, you could have a global static variable in your InfragisticsHelper class like this

   Private Shared Infragistics.Win.ValueList _yes_no_list

and then change the code above in

    Public Shared Function YesNoValueList() As Infragistics.Win.ValueList
        if _yes_no_list Is Nothing Then
            Dim vlYN = new Infragistics.Win.ValueList()
            vlYN.ValueListItems.Add(false, "NO")
            vlYN.ValueListItems.Add(true, "YES")
            vlYN.Key = "_YES_NO_"
            _yes_no_list = vlYN
        End If
        return _yes_no_list
    End Sub

In this way you build the ValueList just at the first use, then you return always the same instance

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top