C# - 在形式格式化时,ListView控件常用方式? [英] C# - Common way to format listview controls on forms?

查看:355
本文介绍了C# - 在形式格式化时,ListView控件常用方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个C#WinForm应用程序(3.5)有许多形式各有不同的列表视图控件。虽然每个ListView控件使用不同的数据集每一个的基本格式是一样的。

基本格式的格式为:

  / * *外观/
  this.lstA.View = View.Details;
  this.lstA.AllowColumnReorder =真;
  this.lstA.CheckBoxes = FALSE;
  this.lstA.FullRowSelect = TRUE;
  this.lstA.GridLines = FALSE;
  this.lstA.Sorting = SortOrder.Ascending;

我想这样做是创建可用于设置列表视图的初始格式的类。

我如何通过列表视图(参照?),以使外观属性可以设置类?

解决方案

要添加到其他答案:

 公共静态类MyExtensionMethods
    {
        公共静态无效InitializeAppearance(这ListView的aListView)
        {
            aListView.View = View.Details;
            aListView.AllowColumnReorder = TRUE;
            aListView.CheckBoxes = FALSE;
            aListView.FullRowSelect = TRUE;
            aListView.GridLines = FALSE;
            aListView.Sorting = SortOrder.Ascending;
        }
    }
}

和你叫它 listview1.InitializeAppearance();

In a C# Winform application (3.5) there are numerous forms each with different listview controls. While each listview control uses different datasets the basic formatting of each remains the same.

Basic formatting takes this form:

  /* appearance */
  this.lstA.View = View.Details;
  this.lstA.AllowColumnReorder = true;
  this.lstA.CheckBoxes = false;
  this.lstA.FullRowSelect = true;
  this.lstA.GridLines = false;
  this.lstA.Sorting = SortOrder.Ascending;

What I would like to do is create a class that can be used to set the initial format of the listview.

How do I pass the listview (by reference?) to the class so that the appearance properties can be set?

解决方案

To add to the other answers:

public static class MyExtensionMethods
    {
        public static void InitializeAppearance(this ListView aListView)
        {
            aListView.View = View.Details;
            aListView.AllowColumnReorder = true;
            aListView.CheckBoxes = false;
            aListView.FullRowSelect = true;
            aListView.GridLines = false;
            aListView.Sorting = SortOrder.Ascending;
        }
    }
}

and you call it listview1.InitializeAppearance();

这篇关于C# - 在形式格式化时,ListView控件常用方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆