Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
555
Strange behavior regarding Columns.Contains()
posted

One of our dialogs contains an ultragrid having a couple of columns, one of them have the key "Path"

Although we the column is realy present in the collection, as we can confirm using the visual studio watch feature, the contains() method seem to fail: 

if (genericDataGrid1.Grid.DisplayLayout.Bands[0].Columns.Contains("Path")) >>> returns false 

//if (genericDataGrid1.Grid.ActiveRow.Cells.Contains("Path")) >>> returns also false 

Thats why we did the following work around:

 

foreach (UltraGridCell cell in genericDataGrid1.Grid.ActiveRow.Cells)

{

         if (cell.Column.Key == "Path")

         {

                       //code to execute

 

 

Any idea

 

Best regards

Kagel

  • 469350
    Suggested Answer
    Offline posted

    Contains searches the collection for an instances of that object in the list. Since the columns collection contains UltraGridColumn objects, Contains will never return true when you pass in a string, because there are no strings in this collection.

    You should use the Exists method, instead, which searches the column Keys.