當前位置: 首頁>>代碼示例>>C#>>正文


C# BindingSource.GetItemProperties方法代碼示例

本文整理匯總了C#中System.Windows.Forms.BindingSource.GetItemProperties方法的典型用法代碼示例。如果您正苦於以下問題:C# BindingSource.GetItemProperties方法的具體用法?C# BindingSource.GetItemProperties怎麽用?C# BindingSource.GetItemProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.BindingSource的用法示例。


在下文中一共展示了BindingSource.GetItemProperties方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetDataSource

    public void SetDataSource(BindingSource source)
    {
      tblMain.Controls.Clear();
      tblMain.RowStyles.Clear();
      tblMain.RowCount = 0;

      var dataTypeArray = Enum.GetValues(typeof(QueryParameter.DataType)).OfType<QueryParameter.DataType>().ToArray();
      var props = source.GetItemProperties(null).OfType<PropertyDescriptor>()
        .Where(p => Filter == null || Filter.Contains(p))
        .OrderBy(p => p.DisplayName ?? p.Name)
        .ToArray();

      foreach (var prop in props)
      {
        tblMain.RowStyles.Add(new RowStyle(SizeType.AutoSize));
        tblMain.RowCount += 1;
        var currRow = tblMain.RowCount - 1;

        var lbl = new Label();
        lbl.AutoSize = true;
        lbl.Text = prop.DisplayName ?? prop.Name;
        lbl.Anchor = AnchorStyles.Left;
        tblMain.Controls.Add(lbl, 0, currRow);

        var currProp = prop as QueryParamDescriptor;
        if (currProp != null)
        {
          var box = new ComboBox();
          box.Anchor = AnchorStyles.Left;
          box.DropDownStyle = ComboBoxStyle.DropDownList;
          box.DataSource = Enum.GetValues(typeof(QueryParameter.DataType));
          tblMain.Controls.Add(box, 1, currRow);
          _initialValues.Add(Array.IndexOf(dataTypeArray, currProp.Param.Type));
          box.SelectedIndexChanged += (s, e) =>
          {
            if (!_isLoaded)
              return;

            tblMain.Controls.Remove(tblMain.GetControlFromPosition(2, currRow));
            var newValue = (QueryParameter.DataType)((ComboBox)s).SelectedValue;
            currProp.Param.Type = newValue;
            switch (newValue)
            {
              case QueryParameter.DataType.Boolean:
                currProp.SetValue(source.Current, default(bool));
                AddControl(source, currProp, typeof(bool), currRow);
                break;
              case QueryParameter.DataType.DateTime:
                currProp.SetValue(source.Current, default(DateTime));
                AddControl(source, currProp, typeof(DateTime), currRow);
                break;
              case QueryParameter.DataType.Decimal:
                currProp.SetValue(source.Current, default(decimal));
                AddControl(source, currProp, typeof(decimal), currRow);
                break;
              case QueryParameter.DataType.Integer:
                currProp.SetValue(source.Current, default(long));
                AddControl(source, currProp, typeof(long), currRow);
                break;
              default:
                currProp.SetValue(source.Current, default(string));
                AddControl(source, currProp, typeof(string), currRow);
                break;
            }
          };
        }

        AddControl(source, prop, null, currRow);
      }
    }
開發者ID:rneuber1,項目名稱:InnovatorAdmin,代碼行數:70,代碼來源:ParameterGrid.cs


注:本文中的System.Windows.Forms.BindingSource.GetItemProperties方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。