模拟Windows Listview的HTC组件[2]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 spanzhang 的 blog

var headerwidth = 0;  //表头宽度
var bodyspan = null;  //体对象
var downtype = -1;  //鼠标点下去的类型,点在不同地方会有不同的类型
var objsizeitem = null;  //拖动线

//列对象
function column(colheader, splitter, style1, style2, style11, style22)
{
 this.colheader = colheader;
 this.splitter = splitter;

 this.style1 = style1; //第一种未选中样式
 if (this.style1 == null) this.style1 = defstyle1;
 this.style2 = style2; //第二种未选中样式
 if (this.style2 == null) this.style2 = defstyle2;
 this.style11 = style11; //第一种选中状态样式
 if (this.style11 == null) this.style11 = defstyle11;
 this.style22 = style22; //第一种选中状态样式
 if (this.style22 == null) this.style22 = defstyle22;
}

//内部函数,事件oncontentready,初始化
function init()
{
 var rs = element.children[0].recordset;

 //基本属性
 columns   = new array();
 selectedrows = new array();
 element.style.overflow = "hidden";

 //构造表头
 header = document.createelement("span");
 with (header.style)
 {
  width  = "2048";
  height = 20;
  backgroundimage = "url(" + headimage + ")";
  cursor = "default";
 }
 element.insertadjacentelement("beforeend", header);
 
 //构造body
 bodyspan = document.createelement("span");
 with (bodyspan.style)
 {
  overflow = "auto";
  cursor = "default";
 }
 bodyspan.attachevent("onscroll", bodyscroll);
 element.insertadjacentelement("beforeend", bodyspan);
 
 datatable = document.createelement("table");
 with (datatable)
 {
  cellspacing = 0;
  cellpadding = 0;
  width = 1;
  bordercolor = "#305d03";
 }
 bodyspan.insertadjacentelement("beforeend", datatable);
 rows = datatable.rows;

 //拖动线
 if (freezecols == 'false')
 {
  objsizeitem = window.document.createelement("div") ;
  with (objsizeitem.style)
  {
   backgroundcolor = "black" ;
   cursor = "col-resize";
   position = "absolute" ;
   border = "none";//"solid 0px" ;
   width = "1px" ;
   zindex = 3000 ;
   visibility = "hidden" ;
  }
  window.document.body.insertadjacentelement("beforeend", objsizeitem);
 }

 //插入所有的列
 var style1, style2, style11, style22;
 for (var i = 0; rs != null && !rs.eof; ++i)
 {
  try {style1 = new string(rs('style1'));} catch(e) {style1 = defstyle1;}
  if (style1 == 'null') style1 = defstyle1;
  try {style2 = new string(rs('style2'));} catch(e) {style2 = defstyle2;}
  if (style2 == 'null') style2 = defstyle2;
  try {style11 = new string(rs('style11'));} catch(e) {style11 = defstyle11;}
  if (style11 == 'null') style11 = defstyle11;
  try {style22 = new string(rs('style22'));} catch(e) {style22 = defstyle22;}
  if (style22 == 'null') style22 = defstyle22;

  addcolumn(rs('width'), rs('text'), style1, style2, style11, style22);

  rs.movenext();
 }
 
 //调整布局
 resize();

本文关键:模拟Windows Listview的HTC组件
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top