Html中使用M$控件系列之 ListView 篇

发表于:2007-06-30来源:作者:点击数: 标签:
html !-- Html中使用M$控件系列之 ListView 篇 CopyRight By Cheery_Ke,2002,All Reserved -- head meta http-equiv=Content-Type content=text/html; charset=gb2312 titleListViewEx/title /head body p object classid=clsid:BDD1F04B-858B-11D1-B16A-00C0
<html>
<!--
Html中使用M$控件系列之 ListView 篇
CopyRight By Cheery_Ke,2002,All Reserved
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ListViewEx</title>
</head>

<body>

<p>
<object classid="clsid:BDD1F04B-858B-11D1-B16A-00C0F0283628" id="ListView1">
  <param name="_ExtentX" value="19844">        <!--宽-->
  <param name="_ExtentY" value="8890">        <!--长-->
  <param name="SortKey" value="0">        <!--排序关键字:按照第 value + 1 列排序-->
  <param name="View" value="3">            <!--显示模式,0:大图标||1:小图标||2:列表||3:报告-->
  <param name="Arrange" value="1">
  <param name="LabelEdit" value="0">        <!--编辑模式,0:手动||1:自动-->
  <param name="SortOrder" value="0">        <!--排序模式,0:升序||1:降序-->
  <param name="Sorted" value="1">        <!--允许手动排序,0:否||1:是-->
  <param name="MultiSelect" value="1">        <!--多选模式,0:启用||1:禁用-->
  <param name="LabelWrap" value="1">
  <param name="HideSelection" value="1">
  <param name="HideColumnHeaders" value="0">    <!--列标题模式,0:显示||1:隐藏-->
  <param name="AllowReorder" value="1">        <!--允许列重排序,0:否||1:是-->
  <param name="Checkboxes" value="0">        <!--复选框模式,0:隐藏||1:显示复选框-->
  <param name="FlatScrollBar" value="0">    <!--平面滚动条,0:否||1:是-->
  <param name="FullRowSelect" value="1">    <!--整行选取模式,0:禁用||1:启用-->
  <param name="GridLines" value="0">        <!--窗格显示,0:隐藏||1:显示-->
  <param name="HotTracking" value="0">        <!--热追踪模式,0:禁用||1:启用-->
  <param name="HoverSelection" value="0">    <!--悬停是否变色,0:否||1:是-->
  <param name="PictureAlignment" value="0">
  <param name="TextBackground" value="0">
  <param name="_Version" value="393217">
  <param name="ForeColor" value="0">        <!--前景颜色,0(黑)<->16777215(白)-->
  <param name="BackColor" value="16777215">    <!--背景颜色,0(黑)<->16777215(白)-->
  <param name="BorderStyle" value="1">        <!--边框模式,0:隐藏||1:显示-->
  <param name="Appearance" value="0">        <!--Style模式,0:平面||1:3D-->
  <param name="MousePointer" value="0">        <!--cursor-->
  <param name="Enabled" value="1">        <!--响应用户,0:否||1:是-->
  <param name="OLEDragMode" value="1">        <!--脱动模式-->
  <param name="OLEDropMode" value="1">        <!--放置模式-->
</object>
</p>

<script language="JScript" for="ListView1" event="columnClick(ColumnHeader)">
<!--//
//排序,响应列标题点击事件
    if (ColumnHeader == @#Column1@#)            //如果点击的是第一列标题
    {
        ListView1.SortKey = 0;            //更改当前排序关键字为第一列
        if (ListView1.SortOrder == @#0@#)
        {
            ListView1.SortOrder = @#1@#;    //反向排序
        }
        else
        {
            ListView1.SortOrder = @#0@#;    //反向排序
        }
    }
    if (ColumnHeader == @#Column2@#)            //如果点击的是第二列标题
    {
        ListView1.SortKey = 1;            //更改当前排序关键字为第二列
        if (ListView1.SortOrder == @#0@#)
        {
            ListView1.SortOrder = @#1@#;    //反向排序
        }
        else
        {
            ListView1.SortOrder = @#0@#;    //反向排序
        }
    }
//-->
</Script>

<script language="JScript" for="ListView1" event="ItemClick(Item)">
<!--//
//读取参数,响应数据行点击事件
    for (i=1; i < 10; i++)
    {
        if ( Item == ListView1.ListItems(i).Text )
        {
            window.location.href = "ListViewEx.htm?" + Item
        }
    }
//-->
</Script>
<Script Language="JavaScript">
<!--//
//初始化,定制结构并填充数据

    //增加一个新的列,方式一:
    ListView1.ColumnHeaders.Add();
    ListView1.ColumnHeaders(1).Width = "0";
    ListView1.ColumnHeaders(1).Key = "C1";
    ListView1.ColumnHeaders(1).Text = "";

    //增加一个新的列,方式二:
    ListView1.ColumnHeaders.Add(2,"C2","Column1","400");

    //增加一个新列。
    ListView1.ColumnHeaders.Add();
    ListView1.ColumnHeaders(3).Width = "400";
    ListView1.ColumnHeaders(3).Key = "C3";
    ListView1.ColumnHeaders(3).Text = "Column2";

    //此处定一个数组,仅做演示排序之用
    var Arr = new Array;
    Arr[1] = "q"
    Arr[2] = "w"
    Arr[3] = "e"
    Arr[4] = "r"
    Arr[5] = "t"
    Arr[6] = "y"
    Arr[7] = "u"
    Arr[8] = "i"
    Arr[9] = "o"

    for (j = 1; j < 10; j++)
    {
        //增加一行数据,参数分别为序号,Key,首列Text
        //也可采用另一种方式:
        //Obj = ListView1.ListItems.Add();
        //ListView1.ListItems(j).Key = @#W@# + j;    此处加一字母@#W@#是因Key值不允许以数字开头
        //ListView1.ListItems(j).Text = j;

        Obj = ListView1.ListItems.Add(j,@#W@# + j , j);

        //增加行中的其他列数据
        Obj.SubItems(1) = j + "qqqq";
        Obj.SubItems(2) = Arr[j] + "wwww"
    }
//-->
</Script>
</body>

</html>

原文转自:http://www.ltesting.net