⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ultragrid.htc

📁 具备表头拖拽、交换列、排序、添加 、修改、删除、选择等等功能的。NET GRID
💻 HTC
📖 第 1 页 / 共 4 页
字号:
<PUBLIC:COMPONENT lightWeight=false>
<PUBLIC:DEFAULTS contentEditable=false tabStop=true/>

<PUBLIC:attach	 event="oncontentready" onevent="initCoolUltraGrid()" />
<PUBLIC:attach	 event="ondetach" onevent="cleanupCoolUltraGrid()" />
<PUBLIC:attach	 event="onresize" onevent="elementOnResize()" />
<PUBLIC:attach	 event="onselectstart" onevent="elementOnSelect()" />
<PUBLIC:attach	 event="onpropertychange" onevent="elementOnPropertyChange()" />

<PUBLIC:property name="borderStyle" value=0 />
<PUBLIC:property name="altRowColor" value="" />
<PUBLIC:property name="selectionStyle" value=2 />
<PUBLIC:property name="selectedRowCount" value=0 />
<PUBLIC:property name="selectedCellCount" value=0 />
<PUBLIC:property name="editStyle" value="auto" />
<PUBLIC:property name="rowCount" value=0 />
<PUBLIC:property name="colCount" value=0 />

<PUBLIC:method   name="getRowByPosition" />
<PUBLIC:method   name="getRowByID" />
<PUBLIC:method   name="getSelectedRow" />
<PUBLIC:method   name="getSelectedCell" />
<PUBLIC:method   name="sortAscending" />
<PUBLIC:method   name="sortDescending" />
<PUBLIC:method   name="removeColumn" />
<PUBLIC:method   name="showFieldChooser" />
<PUBLIC:method   name="doAction" />
<PUBLIC:method   name="resetList" />
<PUBLIC:method   name="beginEdit" />
<PUBLIC:method   name="endEdit" />
<PUBLIC:method   name="addRow" />
<PUBLIC:method   name="deleteRowByPosition" />
<PUBLIC:method   name="deleteRowByID" />
<PUBLIC:method   name="deleteSelectedRows" />
<PUBLIC:method   name="intShowEditObject" />
<PUBLIC:method   name="intShowEditHeadObject" />
<PUBLIC:method   name="intAddRow" />
<PUBLIC:method   name="intDeleteRow" />

<PUBLIC:event    name="onCellSelect" id="cellselect" />
<PUBLIC:event    name="onCellDoubleClick" id="celldblclick" />
<PUBLIC:event    name="onRowSelect" id="rowselect" />
<PUBLIC:event    name="onRowDoubleClick" id="rowdblclick" />
<PUBLIC:event    name="onRowCountChange" id="rowcountchange" />
<PUBLIC:event    name="onRequestAddDialog" id="requestdialogadd" />

<script language="VBScript">

option explicit

dim ie6

dim gridHead
dim gridHeadRow
dim gridBody

dim hiBackgroundColor
dim hiBorderColor
dim transparentImageUrl
dim sortNoneImageUrl
dim sortUpImageUrl
dim sortDownImageUrl
dim posUpImageUrl
dim posDownImageUrl
dim sortAscImageUrl
dim sortDesImageUrl
dim editImageUrl
dim addRowImageUrl
dim delRowImageUrl
dim delRowsImageUrl
dim fieldChooserImageUrl

dim elBorderWidth
dim gridHeadHeight
dim gridHeadWidth

dim inDrag
dim inSize
dim inMenu
dim inEdit
dim hidingObject

dim posOffset
dim sizeStartPos
dim iDragCounter
dim dragHeadHitIndex

dim currentObject
dim cSelectedCells
dim cSelectedRows

dim objEditItem
dim objEditHeadItem
dim editProcRef

dim objHeadMenu
dim mnuProcRef
dim menuHeadIndex
dim prevMenuHeadIndex

dim objWindow

dim objSizeItem

dim objDragItem
dim objDragToItem1
dim objDragToItem2

dim gridRowExtraSpan

inDrag = false
inSize = false
inMenu = false
inEdit = false
hidingObject = false

prevMenuHeadIndex = -1

set currentObject = nothing

set objHeadMenu = nothing
set objWindow = nothing
set objSizeItem = nothing
set objDragItem = nothing
set objDragToItem1 = nothing
set objDragToItem2 = nothing
set gridRowExtraSpan = nothing

ie6 = (instr(window.navigator.appVersion, "MSIE 6.") <> 0)

class clsSelectedObjects
	dim colItems()
	dim itemAdded
	dim lastAddedItem

	private sub Class_Initialize
		itemAdded = false
		set lastAddedItem = nothing
	end sub

	private sub Class_Terminate
		dim i
		if not itemAdded then exit sub
		for i = lbound(colItems) to ubound(colItems)
			set colItems(i) = nothing
		next
		set lastAddedItem = nothing
	end Sub

	public property Get Count
		if not itemAdded then
			Count = 0
		else
			Count = ubound(colItems) + 1
		end if
	end property

	public property Get SelectedObject(index)
		if not itemAdded then
			set SelectedObject = nothing
			exit property
		end if
		set SelectedObject = colItems(index)
	end property

	public property Get LastObject
		if getItemIndex(lastAddedItem) <> -1 then
			set LastObject = lastAddedItem
		else
			set LastObject = nothing
		end if
	end property

	public property Get getObjects
		getObjects = colItems
	end property

	public function QuerySelected(objUnknown)
		QuerySelected = (getItemIndex(objUnknown) <> -1)
	end function

	sub setLastObject(vData)
		set lastAddedItem = vData
	end sub

	public sub AddSingle(objUnknown)
		redim colItems(0)
		set colItems(ubound(colItems)) = objUnknown
		itemAdded = true
		set lastAddedItem = objUnknown
	end sub

	public sub Add(objUnknown)
		if not itemAdded then
			redim preserve colItems(0)
		else
			redim preserve colItems(ubound(colItems) + 1)
		end if
		set colItems(ubound(colItems)) = objUnknown
		itemAdded = true
		set lastAddedItem = objUnknown
	end sub

	public sub Remove(objUnknown)
		dim i
		dim idx
		idx = getItemIndex(objUnknown)
		if idx <> -1 then
			for i = idx to ubound(colItems) - 1
				set colItems(i) = nothing
				set colItems(i) = colItems(i + 1)
			next
			set colItems(ubound(colItems)) = nothing
			if ubound(colItems) - 1 = -1 then itemAdded = false
			redim preserve colItems(ubound(colItems) - 1)
		end if
	end sub

	public sub removeAll
		if not itemAdded then exit sub
		dim i
		for i = lbound(colItems) to ubound(colItems)
			set colItems(i) = nothing
		next
		set lastAddedItem = nothing
		redim colItems(-1)
		itemAdded = false
	end sub

	public function getItemIndex(objUnknown)
		dim i
		if not itemAdded then
			getItemIndex = -1
		exit function
		end if
		for i = lbound(colItems) to ubound(colItems)
			if objUnknown is colItems(i) then
				getItemIndex = i
				exit function
			end if
		next
		getItemIndex = -1
	end function

end class

sub initCoolUltraGrid()
	dim i, w
	dim elChild
	dim imgElement

	element.nowrap = true

	with element.currentStyle
		hiBackgroundColor = .highlightBackgroundColor
		hiBorderColor = .highlightBorderColor
		transparentImageUrl = .transparentImageUrl
		sortNoneImageUrl = .sortNoneImageUrl
		posUpImageUrl = .posUpImageUrl
		posDownImageUrl = .posDownImageUrl
		sortUpImageUrl = .sortUpImageUrl
		sortDownImageUrl = .sortDownImageUrl
		sortAscImageUrl = .sortAscImageUrl
		sortDesImageUrl = .sortDesImageUrl
		editImageUrl = .editImageUrl
		addRowImageUrl = .addRowImageUrl
		delRowImageUrl = .delRowImageUrl
		delRowsImageUrl = .delRowsImageUrl
		fieldChooserImageUrl = .fieldChooserImageUrl
	end with

	setTableBorder()

	select case cint(selectionStyle)
		case 0
			'no selection
		case 1
			set cSelectedCells = new clsSelectedObjects
		case 2
			set cSelectedRows = new clsSelectedObjects
	end select

	set gridHead = getElement(element, "gridHead")
	if gridHead is nothing then
		msgbox "UltraGrid必须有一个表头!"
		exit sub
	end if
	gridHead.align = "left"
	gridHeadHeight = gridHead.offsetHeight

	set gridHeadRow = getElement(gridHead, "gridRow")
	if gridHeadRow is nothing then
		msgbox "UltraGrid必须有一行!"
		exit sub
	end if
	with gridHeadRow
		element.colCount = .children.length
		.insertAdjacentElement "beforeEnd", .document.createElement("SPAN")
		.innerHTML = replace(.innerHTML, "> <", "><")
	end with

	set gridBody = getElement(element, "gridBody")
	if gridBody is nothing then
		msgbox "UltraGrid必须有表格体!"
		exit sub
	end if
	if getElement(gridBody, "gridRow") is nothing then
		msgbox "UltraGrid表格体至少必须有一行!"
		exit sub
	end if
	with gridBody
		element.rowCount = .children.length
		.style.left = "0px"
	end with
	for each elChild in gridBody.children
		if elChild.id <> "cellEdit" then
			with elChild
				if cint(selectionStyle) = 1 then .style.border = "none"
				.innerHTML = replace(.innerHTML, "> <", "><")
			end with
		end if
	next

	initAdditionalElements()

	setRowColors()

	with gridHeadRow
		set gridRowExtraSpan = .children(.children.length - 2)
		for i = 0 to .children.length - 3
			set imgElement = document.createElement("IMG")
			with imgElement
				.src = sortNoneImageUrl
				.id = "srtImg"
				.width = 25
				.height = 11
			end with
			with .children(i)
				.insertAdjacentElement "beforeEnd", imgElement
				on error resume next
				if instr(.width, "%") <> 0 then
					w = (cint(replace(.width, "%", ""))) / 100 * element.offsetWidth
				else
					w = .width
				end if
				.style.width = w
				setColWidth i, .offsetWidth
				gridHeadWidth = gridHeadWidth + .offsetWidth
			end with
			set imgElement = nothing
		next
	end with

	elementOnResize()

	set mnuProcRef = GetRef("parentWindowOnMouseDown")
	set editProcRef = GetRef("editOnKeyDown")

	with gridHead
		.attachEvent "onmousemove", GetRef("gridHeadOnMouseMove")
		.attachEvent "onmousedown", GetRef("gridHeadOnMouseDown")
		.attachEvent "onclick", GetRef("gridHeadOnClick")
		.attachEvent "oncontextmenu", GetRef("gridHeadOnRightClick")
	end with

	with gridBody
		.attachEvent "onscroll", GetRef("gridBodyOnScroll")
		.attachEvent "onmouseover", GetRef("gridBodyOnMouseOver")
		.attachEvent "onmouseout", GetRef("gridBodyOnMouseOut")
		.attachEvent "onclick", GetRef("gridBodyOnClick")
		.attachEvent "ondblclick", GetRef("gridBodyOnDblClick")
	end with

	with element
		.attachEvent "onmousemove",GetRef("elementOnMouseMove")
		.attachEvent "onmouseup",GetRef("elementOnMouseUp")
	end with

	gridHead.style.visibility = "visible"
	gridBody.style.visibility = "visible"
end sub

sub cleanupCoolUltraGrid()
	with gridHead
		.detachEvent "onmousemove", GetRef("gridHeadOnMouseMove")
		.detachEvent "onmousedown", GetRef("gridHeadOnMouseDown")
		.detachEvent "onclick", GetRef("gridHeadOnClick")
		.detachEvent "oncontextmenu", GetRef("gridHeadOnRightClick")
	end with
	with gridBody
		.detachEvent "onscroll", GetRef("gridBodyOnScroll")
		.detachEvent "onmouseover", GetRef("gridBodyOnMouseOver")
		.detachEvent "onmouseout", GetRef("gridBodyOnMouseOut")
		.detachEvent "onclick", GetRef("gridBodyOnClick")
		.detachEvent "ondblclick", GetRef("gridBodyOnDblClick")
	end with
	with element
		.detachEvent "onmousemove",GetRef("elementOnMouseMove")
		.detachEvent "onmouseup",GetRef("elementOnMouseUp")
	end with
	set mnuProcRef = nothing
	set editProcRef = nothing
	set gridHead = nothing
	set gridHeadRow = nothing
	set gridBody = nothing
	set currentObject = nothing
	set cSelectedCols = nothing
	set cSelectedRows = nothing
	if not objEditItem is nothing then objEditItem.removeNode true
	set objEditItem = nothing
	if not objEditHeadItem is nothing then objEditHeadItem.removeNode true
	set objEditHeadItem = nothing
	if not objSizeItem is nothing then objSizeItem.removeNode true
	set objSizeItem = nothing
	if not objDragItem is nothing then objDragItem.removeNode true
	set objDragItem = nothing
	if not objDragToItem1 is nothing then objDragToItem1.removeNode true
	set objDragToItem1 = nothing
	if not objDragToItem2 is nothing then objDragToItem2.removeNode true
	set objDragToItem2 = nothing
	if not objHeadMenu is nothing then objHeadMenu.removeNode true
	set objHeadMenu = nothing
	if not objWindow is nothing then objWindow.removeNode true
	set objWindow = nothing
	if not gridRowExtraSpan is nothing then gridRowExtraSpan.removeNode true
	set gridRowExtraSpan = nothing
end sub


'init functions

sub initAdditionalElements()
	dim txtHTML
	set objEditItem = document.createElement("INPUT")
	with objEditItem
		.id = "cellEdit"
		.className = "coolMask"
		with .style
			.position = "absolute"
			.top = "-100px"
			.left = "-100px"
			.border = "1px solid buttonshadow"
			.height = "0px"
			.width = "0px"
			.padding = "0px"
			.paddingTop = "1px"
			.paddingBottom = "1px"
			.paddingLeft = "2px"
			.margin = "0px"
			.font = "menu"
			.zIndex = 3000
			.visibility = "hidden"
		end with
	end with
	gridBody.insertAdjacentElement "beforeEnd", objEditItem
	set objEditHeadItem = document.createElement("INPUT")
	with objEditHeadItem
		.id = "headCellEdit"
		.className = "coolMask"
		with .style
			.position = "absolute"
			.top = "-100px"
			.left = "-100px"
			.border = "1px solid buttonshadow"
			.height = "0px"
			.width = "0px"
			.padding = "0px"
			.paddingTop = "1px"
			.paddingBottom = "1px"
			.paddingLeft = "2px"
			.margin = "0px"
			.font = "menu"
			.zIndex = 3000
			.visibility = "hidden"
		end with
	end with
	gridHeadRow.insertAdjacentElement "beforeEnd", objEditHeadItem

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -