首页 > 编程 > .NET > 正文

.net datagrid 选择多行

2024-07-10 13:03:05
字体:
来源:转载
供稿:网友
功能:点击datagrid并且按住键盘上的ctrl或shift可选择多行

public class mydatagridclass
inherits datagrid
private m as new arraylist

public readonly property multiselectedindex() as integer()
get
return m.toarray(gettype(integer))
end get
end property

protected overrides sub onmousedown(byval e as system.windows.forms.mouseeventargs)
debug.writeline("datagrid has hit")
dim posdg as point = new point(e.x, e.y)
dim hitdg as datagrid.hittestinfo = hittest(posdg)
if hitdatagrid(hitdg) then
mybase.onmousedown(e)
debug.writeline("mousedown has gogogo.....")
end if
end sub

private function hitdatagrid(byval hit as datagrid.hittestinfo) as boolean
try
select case me.modifierkeys
case keys.control
if hit.row > -1 then
if m.indexof(hit.row) > -1 then
m.remove(hit.row)
me.unselect(hit.row)
else
m.add(hit.row)
me.select(hit.row)
end if
end if
return false
case keys.shift
if hit.row > -1 then
for each indexold as integer in m
me.unselect(indexold)
next
m.clear()
dim i, intstep as integer
if hit.row > me.currentrowindex then
intstep = 1
else
intstep = -1
end if
for i = me.currentrowindex to hit.row step intstep
m.add(i)
me.select(i)
next
end if
return false
case else
for each index as integer in m
me.unselect(index)
next
m.clear()
if hit.type = datagrid.hittesttype.rowheader then
m.add(hit.row)
end if
return true
end select
catch ex as exception
debug.writeline(ex.tostring)
end try
end function
end class


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表