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

📄 ultragrid.htc

📁 具备表头拖拽、交换列、排序、添加 、修改、删除、选择等等功能的。NET GRID
💻 HTC
📖 第 1 页 / 共 4 页
字号:
			cSelectedCells.AddSingle el
			setCellStyle el, "highlighttext", "highlight", "highlight"
			set currentObject = nothing
		end if
		selectedCellCount = cSelectedCells.Count
		cellselect.fire
	elseif cint(selectionStyle) = 2 then
		if (el.tagName = "SPAN") then
			set el = el.parentElement
		end if
		if el.parentElement.className <> "gridBody" then exit function
		if window.event.shiftKey then
			dim lastRow
			set lastRow = cSelectedRows.LastObject
			if not lastRow is nothing then
				dim sIndex, lIndex, vIndex
				sIndex = getElementIndex(el)
				lIndex = getElementIndex(lastRow)
				if sIndex > lIndex then
					vIndex = sIndex
					sIndex = lIndex
					lIndex = vIndex
				end if
				for i = sIndex to lIndex
					with gridBody
						setRowStyle .children(i), "highlighttext", "highlight", "highlight"
						if not cSelectedRows.QuerySelected(.children(i)) then cSelectedRows.Add .children(i)
					end with
				next
				cSelectedRows.setLastObject el
				set lastRow =  nothing
				set currentObject = nothing
			else
				cSelectedRows.AddSingle el
				setRowStyle el, "highlighttext", "highlight", "highlight"
				set currentObject = nothing
			end if
		elseif window.event.ctrlKey then
			if cSelectedRows.QuerySelected(el) then
				cSelectedRows.Remove el
				setRowStyle el, "windowtext", el.style.backgroundColor, el.style.backgroundColor
				setCurrentRow el
			else
				cSelectedRows.Add el
				setRowStyle el, "highlighttext", "highlight", "highlight"
				set currentObject = nothing
			end if
		else
			if cSelectedRows.Count > 0 then
				for i = 0 to cSelectedRows.Count - 1
					set tElement = cSelectedRows.SelectedObject(i)
					setRowStyle tElement, "windowtext", tElement.style.backgroundColor, tElement.style.backgroundColor
					set tElement = nothing
				next
			end if
			cSelectedRows.AddSingle el
			setRowStyle el, "highlighttext", "highlight", "highlight"
			set currentObject = nothing
		end if
		selectedRowCount = cSelectedRows.Count
		rowselect.fire
	end if
	set el = nothing
end function

function gridBodyOnDblClick()
	gridBodyOnClick()
	if cint(selectionStyle) = 0 then
		'no selection
	elseif cint(selectionStyle) = 1 then
		celldblclick.fire
	elseif cint(selectionStyle) = 2 then
		rowdblclick.fire
	end if
end function

function editOnKeyDown
	with window.event
		select case .keyCode
			case 13		'enter key
				hideEditObject true
			case 27		'esc key
				hideEditObject false
		end select
	end with
end function


'externally callable methods

function getRowByPosition(idx)
	set getRowByPosition = nothing
	on error resume next
	set getRowByPosition = gridHeadRow.children(idx)
end function

function getRowByID(id)
	set getRowByID = nothing
	on error resume next
	set getRowByID = gridHeadRow.all(id)
end function

function getSelectedCell(idx)
	set getSelectedCell = nothing
	if cint(selectionStyle) = 1 then
		set getSelectedCell = cSelectedCells.SelectedObject(idx)
	end if
end function

function getSelectedRow(idx)
	set getSelectedRow = nothing
	if cint(selectionStyle) = 2 then
		set getSelectedRow = cSelectedRows.SelectedObject(idx)
	end if
end function

function intAddRow()
	hideMenu()
	requestdialogadd.fire
end function

function addRow(id, colArrray, pos)
	dim i,strHTML, objRowItem, elChild
	for i = lbound(colArrray) to ubound(colArrray)
		strHTML = strHTML & "<span>" & colArrray(i) & "</span>"
	next
	set objRowItem = document.createElement("DIV")
	with objRowItem
		.id = id
		.className = "gridRow"
		.innerHTML = strHTML
		with .style
			.visibility = "hidden"
		end with
	end with
	gridBody.insertAdjacentElement "beforeEnd", objRowItem
	if pos = "" then
		gridBody.insertBefore objRowItem, gridBody.children(gridBody.children.length - 2)
	elseif pos = "atStart" then
		gridBody.insertBefore objRowItem, gridBody.children(0)
	elseif pos = "atEnd" then
		gridBody.insertBefore objRowItem, gridBody.children(gridBody.children.length - 2)
	elseif isNumeric(pos) then
		gridBody.insertBefore objRowItem, gridBody.children(cint(pos) + 1)
	else
		gridBody.insertBefore objRowItem, gridBody.children(gridBody.children.length - 2)
	end if
	if cint(selectionStyle) = 0 then
	elseif cint(selectionStyle) = 1 then
		objRowItem.style.border = "none"
	elseif cint(selectionStyle) = 2 then
	end if
	for i = 0 to gridHeadRow.children.length - 3
		setColWidth i, cint(replace(gridHeadRow.children(i).style.width, "px", ""))
		objRowItem.children(i).style.display = gridHeadRow.children(i).style.display
	next
	setRowColors()
	objRowItem.style.visibility = "visible"
	element.rowCount = gridBody.children.length - 1
	set objRowItem = nothing
	rowcountchange.fire
end function

function intDeleteRow()
	deleteRowByPosition menuRowIndex
end function

function deleteRowByPosition(idx)
	dim objUnknown
	set objUnknown = gridBody.children(idx)
	if not objUnknown is nothing then
		deleteRowByID objUnknown.id
	end if
	set objUnknown = nothing
	rowcountchange.fire
end function

function deleteRowByID(id)
	dim objUnknown, elChild
	set objUnknown = gridBody.all(id)
	if not objUnknown is nothing then
		if cint(selectionStyle) = 0 then
			objUnknown.removeNode true
			setRowColors()
			element.rowCount = gridBody.children.length - 1
		elseif cint(selectionStyle) = 1 then
			for each elChild in objUnknown.children
				if cSelectedCells.QuerySelected(elChild) then
					cSelectedCells.Remove elChild
					selectedCellCount = selectedCellCount - 1
					cellselect.fire
				end if
			next
			objUnknown.removeNode true
			setRowColors()
			element.rowCount = gridBody.children.length - 1
		elseif cint(selectionStyle) = 2 then
			if cSelectedRows.QuerySelected(objUnknown) then
				cSelectedRows.Remove objUnknown
				selectedRowCount = selectedRowCount - 1
				rowselect.fire
			end if
			objUnknown.removeNode true
			setRowColors()
			element.rowCount = gridBody.children.length - 1
		end if
	end if
	set objUnknown = nothing
	rowcountchange.fire
end function

function deleteSelectedRows()
	dim i
	if cint(selectionStyle) = 2 then
		for i = lbound(cSelectedRows.colItems) to ubound(cSelectedRows.colItems)
			if not cSelectedRows.colItems(i) is nothing then cSelectedRows.colItems(i).removeNode true
		next
		resetList()
		rowselect.fire
		element.rowCount = gridBody.children.length - 1
	end if
	rowcountchange.fire
end function

sub resetList()
	if cint(selectionStyle) = 0 then
		setRowColors()
	elseif cint(selectionStyle) = 1 then
		setRowColors()
		cSelectedCells.removeAll
		selectedCellCount = 0
	elseif cint(selectionStyle) = 2 then
		setRowColors()
		cSelectedRows.removeAll
		selectedRowCount = 0
	end if
end sub


'get routines

function getElement(el, strClassName)
	dim elChild
	for each elChild in el.children
		if elChild.className = strClassName then
			set getElement = elChild
			exit function
		end if
	next
	set getElement = nothing
end function

function getElementIndex(el)
	dim i
	with el
		for i = 0 to .parentElement.children.length - 1
			if el is .parentElement.children(i) then
				getElementIndex = i
				exit function
			end if
		next
	end with
end function

function getGridRowWidth()
	dim i
	gridHeadWidth = 0
	with gridHeadRow
		for i = 0 to .children.length - 3
			with .children(i)
				if .style.display <> "none" then gridHeadWidth = gridHeadWidth + .offsetWidth
			end with
		next
	end with
end function

function getVisibleCount()
	dim i, count
	count = 0
	with gridHeadRow
		for i = 0 to .children.length - 3
			if .children(i).style.display <> "none" then
				count = count + 1
			end if
		next
	end with
	getVisibleCount = count
end function

function parentIsGrid(el)
	do while (not el is nothing)
		set el = el.parentElement
		if el is gridBody or el is gridHead then
			parentIsGrid = true
			exit function
		end if
	loop
	parentIsGrid = false
end function


'set routines

sub setTableBorder()
	with element
		select case .borderStyle
			case 0
				.style.border = ""
				posOffSet = 3
			case 1
				.style.border = "1 solid black"
				posOffSet = 4
			case 2
				.style.borderLeft = "1 buttonshadow solid"
				.style.borderTop = "1 buttonshadow solid"
				.style.borderBottom = "1 buttonhighlight solid"
				.style.borderRight = "1 buttonhighlight solid"
				posOffSet = 4
			case 3
				.style.border = "2 inset window"
				posOffSet = 5
		end select
		elBorderWidth = (.offsetWidth - .clientWidth)
	end with
end sub

sub setGridHeadWidth(elClientHeight, elClientWidth, gridBodyClientHeight)
	dim horScrollHeight
	horScrollHeight = (elClientHeight - gridBodyClientHeight) - gridHeadHeight
	if elClientWidth >= gridHeadWidth and horScrollHeight < 1 then
		gridHeadRow.style.marginLeft = 0
		gridBody.scrollLeft = 0
		gridRowExtraSpan.style.width = elClientWidth - gridHeadWidth
	else
		gridRowExtraSpan.style.width = horScrollHeight + elBorderWidth
	end if
end sub

sub setRowColors()
	dim i, elChild
	if element.altRowColor <> "" then
		for i = 0 to gridBody.children.length - 1
			if gridBody.children(i).id <> "cellEdit" then
				with gridBody.children(i).style
					if ((i\2) * 2) = i then
						.borderColor = element.altRowColor
						.backgroundColor = element.altRowColor
					else
						.borderColor = "window"
						.backgroundColor = "window"
					end if
					setRowStyle gridBody.children(i), "windowtext", .backgroundColor, .backgroundColor
					if cint(selectionStyle) = 0 then
						'no selection
					elseif cint(selectionStyle) = 1 then
						for each elChild in gridBody.children(i).children
							if cSelectedCells.QuerySelected(elChild) then
								setCellStyle elChild, "highlighttext", "highlight", "highlight"
							else
								setCellStyle elChild, "windowtext", .backgroundColor, .backgroundColor
							end if
						next
					elseif cint(selectionStyle) = 2 then
						if cSelectedRows.QuerySelected(gridBody.children(i)) then
							setRowStyle gridBody.children(i), "highlighttext", "highlight", "highlight"
						end if
					end if
				end with
			end if
		next
	end if
end sub

sub setCurrentCell(el)
	if not currentObject is nothing then
		with currentObject
			setCellStyle currentObject, "windowtext", .style.backgroundColor, .parentElement.runtimeStyle.backgroundColor
		end with
	end if
	if not el is nothing then
		setCellStyle el, "windowtext", hiBackgroundColor, hiBorderColor
	end if
	set currentObject = el
end sub

sub setCurrentRow(el)
	if not currentObject is nothing then
		with currentObject
			setRowStyle currentObject, "windowtext", .style.backgroundColor, .style.backgroundColor
		end with
	end if
	if not el is nothing then
		setRowStyle el, "windowtext", hiBackgroundColor, hiBorderColor
	end if
	set currentObject = el
end sub

sub setCellStyle(objUnknown, fontColor, bgColor, borderColor)
	with objUnknown
		.style.borderColor = borderColor
		with .runtimeStyle
			.color = fontColor
			.backgroundColor = bgColor
		end with
	end with
end sub

sub setRowStyle(objUnknown, fontColor, bgColor, borderColor)
	with objUnknown
		.style.borderColor = borderColor
		with .runtimeStyle
			.color = fontColor
			.backgroundColor = bgColor
		end with
	end with
end sub

sub setColWidth(intCol, intWidth)
	dim elChild
	for each elChild in gridBody.children
		if elChild.id <> "cellEdit" then
			with elChild.children(intCol).style
				if cint(selectionStyle) = 0 then
					.border = "none"
					if intCol = elChild.children.length - 1 then
						.width = intWidth - 2
					else
						.width = intWidth
					end if
				elseif cint(selectionStyle) = 1 then
					if .borderWidth <> "1px" then
						.borderWidth = "1px"
						.borderStyle = "solid"
						.borderColor = elChild.style.backgroundColor
					end if
					.width = intWidth
				elseif cint(selectionStyle) = 2 then
					.border = "none"
					if intCol = elChild.children.length - 1 then
						.width = intWidth - 2
					else
						.width = intWidth
					end if
				end if
			end with
		end if
	next
end sub

sub setOffsets(offsetX, offsetY)
    dim el
    set el = element
	do while (not el is nothing)
		offsetX = offsetX + el.offsetLeft - el.scrollLeft
		offsetY = offsetY + el.offsetTop - el.scrollTop
		set el = el.offsetParent
	loop
    set el = nothing
end sub

sub setElementOffsets(inElement, toElement, offsetX, offsetY)
    dim el
    set el = inElement
	do while (not el is toElement)
		offsetX = offsetX + el.offsetLeft - el.scrollLeft
		offsetY = offsetY + el.offsetTop - el.scrollTop
		set el = el.offsetParent
	loop
    set el = nothing
end sub


'menu routines

sub showMenu(elMenu, x, y)
	dim intRightEdge
	dim intBottomEdge

⌨️ 快捷键说明

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