In this lesson, you will learn how to access the properties of a list form's Grid Control in WinForms and ASP.NET Web applications. For this purpose, new View Controllers will be implemented. They will set alternating row colors in all List Views represented by the built-in GridListEditor and ASPxGridListEditor.

在本课中,您将学习如何在 WinForms 和ASP.NET Web 应用程序中访问列表窗体的网格控件的属性。为此,将实施新的视图控制器。他们将设置由内置网格编辑器和 ASPxGridListEditor 表示的所有列表视图中的交替行颜色。

Note 注意

Before proceeding, take a moment to review the following lessons.

在继续之前,请花点时间复习以下课程。

Add a Simple Action

添加简单操作

Access Editor Settings in a WinForms Application

访问 WinForms 应用程序中的编辑器设置

  • Since the functionality to be implemented is specific to the WinForms platform, changes will be made to the MySolution.Module.Win project. Add a View Controller to the Controllers folder in the MySolution.Module.Win project, as described in the Add a Simple Action lesson. Name it "WinAlternatingRowsController".
  • Invoke the Controller's Designer. In the Properties window, set the TargetViewType property to the "ListView" value. This is necessary because the Controller should appear in List Views only.

  • 由于要实现的功能特定于 WinForms 平台,因此将对 MySolution.module.Win 项目进行更改。将视图控制器添加到 MySolution.module.Win 项目中的控制器文件夹,如"添加简单操作"一课中所述。将其命名为"赢控制器控制器"。

  • 调用控制器的设计器。在"属性"窗口中,将 TargetViewType 属性设置为"ListView" 值。这是必需的,因为控制器应仅出现在列表视图中。

  • Since you are going to access the settings of the List View's Grid Control, you need to ensure that it has already been created. This is why you need to subscribe to the Controller's ViewControlsCreated event. In the Properties window, switch to the Events view and double-click the ViewControlsCreated event. Handle the event as shown below.

  • 由于您将要访问列表视图的网格控件的设置,因此您需要确保已创建该设置。这就是为什么您需要订阅控制器的视图控制创建事件。在"属性"窗口中,切换到"事件"视图并双击"查看控制创建"事件。处理事件,如下所示。

    using System.Drawing;
    using DevExpress.ExpressApp.Win.Editors;
    using DevExpress.XtraGrid.Views.Grid;
    //...
    private void WinAlternatingRowsController_ViewControlsCreated(object sender, EventArgs e) {
    GridListEditor listEditor = ((ListView)View).Editor as GridListEditor;
    if (listEditor != null) {
    GridView gridView = listEditor.GridView;
    gridView.OptionsView.EnableAppearanceOddRow = true;
    gridView.Appearance.OddRow.BackColor = Color.FromArgb(, , );
    }
    }

    As you can see in the code above, to access a list form's Grid, you should first get the ListEditor, which is the object that binds data to a Grid. To get the ListEditor, use the ListView.Editor property of the required List View. There are several types of built-in WinForms ListEditors. The code above is implemented when the current List View is represented by a GridListEditor. This ListEditor represents data via the XtraGrid control. Use the GridListEditor.GridView property to access this control.

如您在上面的代码中所示,要访问列表窗体的网格,应首先获取 ListEditor,这是将数据绑定到网格的对象。要获取列表编辑器,请使用所需列表视图的 ListView.编辑器属性。有几种类型的内置 WinForms 列表编辑器。当当前列表视图由 GridListEditor 表示时,

将实现上述代码。此列表编辑器表示通过 XtraGrid 控件的数据。使用网格编辑器.GridView 属性访问此控件。

  • Run the WinForms application and select an item in the navigation control. The data rows now have alternating colors.

  • 运行 WinForms 应用程序并在导航控件中选择一个项目。数据行现在具有交替的颜色。

Access Editor Settings in an ASP.NET Application

访问ASP.NET应用程序中的编辑器设置

  • As the functionality to be implemented is specific to the ASP.NET platform, changes will be made to MySolution.Module.Web in this lesson. Add a View Controller to the Controllers folder in the MySolution.Module.Web project, as described in the Add a Simple Action lesson. Name it "WebAlternatingRowsController".
  • Invoke the Controller's Designer. In the Properties window, set the TargetViewType property to the "ListView" value. This is necessary because the Controller should appear in List Views only.

  • 由于要实现的功能特定于ASP.NET平台,因此本课将对 MySolution.module.Web 进行更改。将视图控制器添加到 MySolution.module.Web 项目中的控制器文件夹中,如"添加简单操作"一课中所述。将其命名为"网络控制器"。

  • 调用控制器的设计器。在"属性"窗口中,将 TargetViewType 属性设置为"ListView" 值。这是必需的,因为控制器应仅出现在列表视图中。

  • Since you are going to access the settings of the List View's Grid Control, you need to ensure that it has already been created. This is why you need to subscribe to the Controller's ViewControlsCreated event. In the Properties window, switch to the Events view and double-click the ViewControlsCreated event. Handle the event as shown below.

由于您将要访问列表视图的网格控件的设置,因此您需要确保已创建该设置。这就是为什么您需要订阅控制器的视图控制创建事件。在"属性"窗口中,切换到"事件"视图并双击"查看控制创建"事件。处理事件,如下所示。

using System.Drawing;
using DevExpress.ExpressApp.Web.Editors.ASPx;
//...
private void WebAlternatingRowsController_ViewControlsCreated(object sender, EventArgs e) {
ASPxGridListEditor listEditor = ((ListView)View).Editor as ASPxGridListEditor;
if (listEditor != null)
listEditor.Grid.Styles.AlternatingRow.BackColor = Color.FromArgb(, , );
}
  • As you can see in the code above, to access a list form's Grid, you should first get the ListEditor, which is the object that binds data to a Grid. To get the ListEditor, use the ListView.Editor property of the required List View. There are several types of built-in ASP.NET ListEditors. The code above is implemented when the current List View is represented by an ASPxGridListEditor. This ListEditor represents data via the ASPxGridView control. To access this control, the ASPxGridListEditor.Grid property is used.
  • 如您在上面的代码中所示,要访问列表窗体的网格,应首先获取 ListEditor,这是将数据绑定到网格的对象。要获取列表编辑器,请使用所需列表视图的 ListView.编辑器属性。有几种类型的内置ASP.NET列表编辑器。当当前列表视图由 ASPxGridList 编辑器表示时,将实现上述代码。此列表编辑器表示通过 ASPxGridView 控件的数据。要访问此控件,将使用 ASPxGridListEditor.Grid 属性。
  • Run the ASP.NET application. Select an item in the navigation control and ensure that the rows background is changed.

  • 运行ASP.NET应用程序。在导航控件中选择一个项目,并确保更改行背景。

Note 注意

Due to WinForms and ASP.NET platform specifics, View Item and List Editor controls may not be immediately ready for customization after the control is created. Consider handling additional platform-dependent events or using alternative approaches if the customizations above do not have any effect.

由于 WinForms 和ASP.NET平台细节,在创建控件后,视图项和列表编辑器控件可能不会立即准备好进行自定义。如果上述自定义项没有任何效果,请考虑处理其他与平台相关的事件或使用替代方法。

  • WinForms:

    Handle the System.Windows.Forms.Control

object's HandleCreated, VisibleChanged or ParentChanged

  • WinForms:

处理系统.Windows.窗体.控件

对象的句柄已创建、可见更改或父更改

  • events. You can also handle the Load (or similar) event if the current control type exposes it.

  • 事件。如果当前控件类型公开了"加载"(或类似)事件,也可以处理该事件。
  • ASP.NET:

    Handle the System.Web.UI.Control

object's Load or Init

  • ASP.NET:
    处理系统.Web.UI.控件
    对象的加载或 Init
  • server-side event. In certain cases, you may need to handle the WebWindow.PagePreRender event. Use the WebWindow.CurrentRequestWindowstatic property to get the current WebWindow object. You can also perform certain customizations on the client side using JavaScript (see Client-Side Functionality Overview).

  • 服务器端事件。在某些情况下,您可能需要处理 WebWindow.pageprein 事件。使用 WebWindow.CurrentRequest 静态属性获取当前 WebWindow 对象。您还可以使用 JavaScript 在客户端执行某些自定义(请参阅客户端功能概述)。

These additional platform-dependent events indicate the controls' "ready" state: a control has been added to the form controls hierarchy or has been bound to data. Contact us using the Support Center

if you need additional help to perform customizations.

这些与平台相关的其他事件指示控件的"就绪"状态:控件已添加到窗体控件层次结构中或已绑定到数据。使用支持中心联系我们如果您需要其他帮助来执行自定义。

Access Grid Control Properties 访问网格控件属性的更多相关文章

  1. HTML5 UI框架Kendo UI Web中如何实现Grid网格控件本地化

    Kendo UI Web包含数百个创建HTML5 web app的必备元素,包括UI组件.数据源.验证.一个MVVM框架.主题.模板等. 为了使得产品可以符合不同市场的本地化需求和语言,Kendo U ...

  2. [转] c#中 多线程访问winform控件

    原文 c#中多线程访问winform控件的若干问题小结 我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题.然而我们并不能用传统方法来解决这个问题,下面我将详细的 ...

  3. 多线程访问winform控件出现异常的解决方法

    一.  多线程访问winform控件出现异常的解决方法 1.  问题描述<1> 如果创建某控件的线程之外的其他线程试图调用该控件,则会引发一个 InvalidOperationExcept ...

  4. 理解SynchronizationContext,如何在Winform里面跨线程访问UI控件

    SynchronizationContext 类是一个基类,可提供不带同步的自由线程上下文. 此类实现的同步模型的目的是使公共语言运行库内部的异步/同步操作能够针对不同的异步模型采取正确的行为.此模型 ...

  5. 实现Winform 跨线程安全访问UI控件

    在多线程操作WinForm窗体上的控件时,出现“线程间操作无效:从不是创建控件XXXX的线程访问它”,那是因为默认情况下,在Windows应用程序中,.NET Framework不允许在一个线程中直接 ...

  6. 跨线程访问UI控件时的Lambda表达式

    工作中经常会用到跨线程访问UI控件的情况,由于.net本身机制,是不允许在非UI线程访问UI控件的,实际上跨线程访问UI控件还是 将访问UI的操作交给UI线程来处理的, 利用Control.Invok ...

  7. 在C#或者SWT上跨进程访问SWT控件的问题

    可能为了进程安全,无论是C#的Form还是Eclipse的SWT,都不允许跨进程访问控件. 通俗一点说就是: A进程创建了控件Widget,若想在B进程中访问控件Widget就会报错,必须在创建Wid ...

  8. mfc Picture Control 控件属性

    知识点: Picture Control 控件属性 CStatic类 图片控件 图片控件使用 一.图片控件属性 Picture Control 属性: Type:Frame //框架 Type:Etc ...

  9. AJAX Control Toolkit的AsynFileUpload控件资料收集

    基于AJAX的文件上传显示进度条实现 http://plkong.iteye.com/blog/238159 asp.net ajax AjaxFileUpload使用 多文件上传 http://bl ...

随机推荐

  1. golang中copy文件时,buffer设多大值合适,性能对比

    在go语言中,copy文件时,大文件使用buffer缓冲,可以明显加快时间, 但这个值多大合适呢? 除了考虑计算机的硬件资源,还要考虑CP文件的大小. 如果都是100m之内的小文件,一次CP完就可以. ...

  2. Caffe源码-InsertSplits()函数

    InsertSplits()函数 在Net初始化的过程中,存在一个特殊的修改网络结构的操作,那就是当某层的输出blob对应多个其他层的输入blob时,会在输出blob所在层的后面插入一个新的Split ...

  3. Django-Model 大全

      ORM 映射关系: 表名 <-------> 类名 字段 <-------> 属性 表记录 <-------> 类实例对象 创建表(建立模型) 实例:我们来假定 ...

  4. MongoDB(五):更新文档、删除文档

    1. 更新文档 MongoDB的uptade()和save()方法用于将集合中的文档更新.update()方法更新现有文档中的值,而save()方法是传递文档数据替换现有文档.从3.2版本开始,Mon ...

  5. springIOC及设计模式

    一.IOC的概念: 控制反转(inversion of control)和依赖注入(dependency injection)其实是同一个概念.当某个方法需要另外一个对象协助的时候,传统的方法就是有调 ...

  6. VMware 虚拟机黑屏问题

    VMware Workstation 14打开虚拟机黑屏解决方法 听语音 浏览:0 | 更新:2017-11-21 16:56 | 标签:操作系统 虚拟机 VMWARE 1 2 3 4 分步阅读 最近 ...

  7. IT兄弟连 HTML5教程 CSS3属性特效 自定义文字

    字体使用是网页设计中不可或缺的一部分.经常地,我们希望在网页中使用某一特定字体,但是该字体并非主流操作系统的内置字体,这样用户在浏览页面的时候就有可能看不到真实的设计.美工设计师最常做的办法是把想要的 ...

  8. Oracle - exp实战

    一.概述 exp/imp是oracle中的一个逻辑导出和导入工具,假想一个场景,当我们使用exp命令在对用户进行导出的时候,如果该用户中的某些表的数据有修改,或表结构进行了修改,或者表被删除,那么我们 ...

  9. Ligg.EasyWinApp-101-Ligg.EasyWinForm: Application--启动,传入参数、读取Application级别配置文件、验证密码、软件封面、启动登录、StartForm

    首先请在VS里打开下面的文件,我们将对源码分段进行说明: 步骤1:读取debug.ini文件 首先读取当前文件夹(.\Clients\Form)的debug.ini文件,该文件的args用于调试时传参 ...

  10. 下拉框移动 jquery

    <%@ page contentType="text/html;charset=UTF-8" language="java" %><html& ...