Esempio n. 1
0
        private int GetCurrentValueIndex(GridEntry gridEntry) {

            if (!gridEntry.Enumerable) {
                return -1;
            }

            try {
                object[] values = gridEntry.GetPropertyValueList();
                object value = gridEntry.PropertyValue;
                string textValue = gridEntry.TypeConverter.ConvertToString(gridEntry, value);

                if (values != null && values.Length > 0) {
                    string itemTextValue;
                    int stringMatch = -1;
                    int equalsMatch = -1;
                    for (int i = 0; i < values.Length; i++) {

                        object curValue = values[i];

                        // check real values against string values.
                        itemTextValue = gridEntry.TypeConverter.ConvertToString(curValue);
                        if (value == curValue || 0 == String.Compare(textValue, itemTextValue, true, CultureInfo.InvariantCulture)) {
                            stringMatch = i;
                        }
                        // now try .equals if they are both non-null
                        if (value != null && curValue != null && curValue.Equals(value)) {
                            equalsMatch = i;
                        }

                        if (stringMatch == equalsMatch && stringMatch != -1) {
                            return stringMatch;
                        }
                    }

                    if (stringMatch != -1) {
                        return stringMatch;
                    }

                    if (equalsMatch != -1) {
                        return equalsMatch;
                    }
                }
            }
            catch (Exception e) {
                Debug.Fail(e.ToString());
            }
            return -1;

        }
 private int GetCurrentValueIndex(GridEntry gridEntry)
 {
     if (gridEntry.Enumerable)
     {
         try
         {
             object[] propertyValueList = gridEntry.GetPropertyValueList();
             object propertyValue = gridEntry.PropertyValue;
             string strA = gridEntry.TypeConverter.ConvertToString(gridEntry, propertyValue);
             if ((propertyValueList != null) && (propertyValueList.Length > 0))
             {
                 int num = -1;
                 int num2 = -1;
                 for (int i = 0; i < propertyValueList.Length; i++)
                 {
                     object obj3 = propertyValueList[i];
                     string strB = gridEntry.TypeConverter.ConvertToString(obj3);
                     if ((propertyValue == obj3) || (string.Compare(strA, strB, true, CultureInfo.InvariantCulture) == 0))
                     {
                         num = i;
                     }
                     if (((propertyValue != null) && (obj3 != null)) && obj3.Equals(propertyValue))
                     {
                         num2 = i;
                     }
                     if ((num == num2) && (num != -1))
                     {
                         return num;
                     }
                 }
                 if (num != -1)
                 {
                     return num;
                 }
                 if (num2 != -1)
                 {
                     return num2;
                 }
             }
         }
         catch (Exception)
         {
         }
     }
     return -1;
 }