コード例 #1
0
        public void SetExpectedEditType(object sampleValue)
        {
            Type sampleValueType = GetEditType();

            if (sampleValueType == null)
            {
                // set to read only
                expectedValueType = null;
                DropDownEvent.PopulateDropdown(valueType, new string[] { "read only" }, this, null, 0, false);
            }
            else
            {
                if (sampleValueType != expectedValueType)
                {
                    // set to specific type
                    if (sampleValueType == typeof(object))
                    {
                        sampleValueType = sampleValue.GetType();
                        int defaultChoice = -1;
                        if (defaultChoice < 0 && CodeConvert.IsIntegral(sampleValueType))
                        {
                            defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(long));
                        }
                        if (defaultChoice < 0 && CodeConvert.IsNumeric(sampleValueType))
                        {
                            defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(double));
                        }
                        if (defaultChoice < 0)                          // && sampleValueType == typeof(string)) {
                        {
                            defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(string));
                        }
                        List <string> options = defaultValueTypes.ConvertAll(kvp => kvp.Value);
                        DropDownEvent.PopulateDropdown(valueType, options, this, SetEditType, defaultChoice, true);
                        cHeader.columnSetting.type = defaultValueTypes[defaultChoice].Key;
                    }
                    else
                    {
                        DropDownEvent.PopulateDropdown(valueType, new string[] { sampleValueType.ToString() }, this, null, 0, false);
                        cHeader.columnSetting.type = sampleValueType;
                    }
                    expectedValueType = sampleValueType;
                }
            }
        }