动态更改 ASPxGridView 的编辑器类型

发布于 2024-08-05 03:20:05 字数 734 浏览 3 评论 0原文

我有一个来自 DevExpress 的 ASPxGridView,其中包含来自 ObjectDataSource 的数据。我的数据行对象公开 ParameterName、ParameterType 和 ParameterValue 等属性。

//Properties, constructor and private fields code omitted for clarity
public class InputParameterDescription
{
   public string ParameterName;

   public Type ParameterType;

   public int ParameterPrecision;

   public string ParameterDescription;
}

ParameterValue 始终是 ParameterType 属性指示的类型的对象。事实上,我使用了几种类型——Int32、Double、String 或 Boolean。当我在网格中显示值并且用户单击“编辑”时,始终使用文本框编辑 ParameterValue。是否可以根据 ParameterType 更改此列的编辑器?我希望我的用户使用 SpinEdit 处理整数,使用复选框处理布尔值等。

事实上,这就是人们使用 DevExpress Delphi 网格的方式 - TdxGrid 和 TcxGrid(OnGetProperties 事件)。我在 DevExpress 论坛上问过这个问题,但没有得到任何答案:(

I have an ASPxGridView from DevExpress fed with data from ObjectDataSource. My data row objects expose properties such ParameterName, ParameterType and ParameterValue.

//Properties, constructor and private fields code omitted for clarity
public class InputParameterDescription
{
   public string ParameterName;

   public Type ParameterType;

   public int ParameterPrecision;

   public string ParameterDescription;
}

ParameterValue is always an object of type indicated by ParameterType property. In fact, I use few types – Int32, Double, String or Boolean. When I display values in a grid and user clicks “Edit” a ParameterValue is always edited with TextBox. Is it possible to change editor for this column according to ParameterType? I want my users to use SpinEdit for integers, checkbox for Boolean, etc.

In fact, this is the way people have been working with DevExpress Delphi grids - TdxGrid and TcxGrid (OnGetProperties event). I have asked this question in DevExpress forum, but haven’t got any answer :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笛声青案梦长安 2024-08-12 03:20:05

您可以在该列上创建一个模板来为您进行切换。类似于:

public class SwitchTemplate : ITemplate
{
   public void Instantiate(Control container)
   {
      GridViewDataItemTemplateContainer cnt = (GridViewDataItemTemplateContainer) container;
      switch( GetStringParameterTypeFromDataItem(cnt.DataItem) )
      {
         case "Int32":
            container.Controls.Add( new ASPxSpinEdit() { ... } );
            break;

         case "DateTime":
            container.Controls.Add( new ASPxDateEdit() { ... } );
            break;

         case "String":
            container.Controls.Add( new ASPxTextBox() { ... } );
            break;

         ...
      }  
   }
}

然后您只需将此模板指定为该列的 EditItemTemplate:

myGrid.Columns["MyColumnName"].EditItemTemplate = new SwitchTemplate()

You could create a template on that column that would do the switch for you. Something like:

public class SwitchTemplate : ITemplate
{
   public void Instantiate(Control container)
   {
      GridViewDataItemTemplateContainer cnt = (GridViewDataItemTemplateContainer) container;
      switch( GetStringParameterTypeFromDataItem(cnt.DataItem) )
      {
         case "Int32":
            container.Controls.Add( new ASPxSpinEdit() { ... } );
            break;

         case "DateTime":
            container.Controls.Add( new ASPxDateEdit() { ... } );
            break;

         case "String":
            container.Controls.Add( new ASPxTextBox() { ... } );
            break;

         ...
      }  
   }
}

Then you just need to specify this template as the EditItemTemplate of the column:

myGrid.Columns["MyColumnName"].EditItemTemplate = new SwitchTemplate()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文