国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

[NET.VB]小問題集錦(供初學者參考)

2024-07-21 02:20:57
字體:
來源:轉載
供稿:網友
聲明:

1、所有代碼不注明出處的皆為本人所寫

2、所有代碼均在本機調試通過

3、本貼適用于初學者(本人也是)

4、歡迎各位仁兄斧正,提供想法或代碼

5、本人力求每日補充內容

6、非本人同意,請勿轉載本人所寫的代碼

7、各位說要不要上面第6條?

8、哈,聲明是這樣寫的嗎,一點都不嚴肅,也不規(guī)范

水如煙 2004.7.19

[控件類]

treeview

1、給節(jié)點加個tooltip(2004.7.19)

private tmptreenode as treenode
private mtreeviewtooltip as new tooltip

private sub treeview1_mousemove(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles treeview1.mousemove
dim mnode as treenode
mnode = me.treeview1.getnodeat(e.x, e.y)
'當前沒節(jié)點
if mnode is nothing then
mtreeviewtooltip.settooltip(me.treeview1, nothing)
exit sub
end if
'超過當前node的邊界
if mnode.bounds.right < e.x orelse mnode.bounds.left > e.x then
mtreeviewtooltip.settooltip(me.treeview1, nothing)
exit sub
end if
'同一個node
if mnode is tmptreenode then
exit sub
end if
mtreeviewtooltip.automaticdelay = 500
mtreeviewtooltip.settooltip(me.treeview1, mnode.text)
tmptreenode = mnode
end sub



datagrid

1、自適應各列長度(2004.7.19)

'定義一個字段信息類
private class columninfo
public [name] as string
public [datatype] as string
public maxwidth as integer = 0
public sub comparestringlength(byval mstring as string)
dim mlength as integer
mlength = system.text.encoding.default.getbytes(mstring).length()
if maxwidth < mlength then maxwidth = mlength
end sub
public function columnwidth(byval mdatagrid as datagrid) as integer
dim mgraphics as graphics = mdatagrid.creategraphics
dim mcolwidth as single
mcolwidth = mgraphics.measurestring(new string(ctype("a", char), maxwidth), mdatagrid.font).width + 2
return ctype(mcolwidth, integer)
end function
end class


private sub makedatagridautoextend(byval mdatagrid as datagrid)
'判斷mdatagrid數(shù)據(jù)源類型
'如果綁定的是dataset或dataviewmanager或沒有綁定任何數(shù)據(jù)源,則退出,
if typeof mdatagrid.datasource is system.data.dataset orelse _
typeof mdatagrid.datasource is system.data.dataviewmanager orelse _
mdatagrid.datasource is nothing then exit sub

'以下分別考慮兩種數(shù)據(jù)源,一是dataview,一是datatable
dim dt as datatable
if typeof mdatagrid.datasource is system.data.dataview then
dt = ctype(mdatagrid.datasource, dataview).table
else
dt = ctype(mdatagrid.datasource, datatable)
end if

'取各字段信息
dim mcolumninfo(dt.columns.count - 1) as columninfo

dim i as integer = 0

dim mcolumn as datacolumn
for each mcolumn in dt.columns
dim minfo as new columninfo
with minfo
.name = mcolumn.columnname
.datatype = mcolumn.datatype.tostring
.comparestringlength( mcolumn.columnname)
end with
mcolumninfo(i) = minfo
i += 1
next

'取各字段的最大長度
dim mrow as datarow
for each mrow in dt.rows
for i = 0 to dt.columns.count - 1
if not isdbnull(mrow(i)) then
mcolumninfo(i).comparestringlength(ctype(mrow(i), string))
end if
next
next

'建datagridtablestyle
dim ts as new datagridtablestyle
ts.mappingname = dt.tablename

for i = 0 to dt.columns.count - 1
if mcolumninfo(i).datatype.equals("system.boolean") then
'這是boolean字段
dim blncol as new datagridboolcolumn
with blncol
.mappingname = mcolumninfo(i).name
.headertext = mcolumninfo(i).name
.width = mcolumninfo(i).columnwidth(mdatagrid)
.nulltext = ""
end with
ts.gridcolumnstyles.add(blncol)
else
'非boolean字段
dim txtcol as new datagridtextboxcolumn
with txtcol
.mappingname = mcolumninfo(i).name
.headertext = mcolumninfo(i).name
.width = mcolumninfo(i).columnwidth(mdatagrid)
.nulltext = ""
.readonly = false '這里可以設置為只讀
.format = "" '這里可以設置顯示格式,要顯示日時分秒的就在這設
end with
ts.gridcolumnstyles.add(txtcol)
end if
next

mdatagrid.tablestyles.clear()
mdatagrid.tablestyles.add(ts)
'至于其它的功能,比如綁定事件之類的,后面再補充
end sub
 

'調用
private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click
makedatagridautoextend(me.datagrid1)
end sub
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 丰台区| 柳林县| 武夷山市| 昆明市| 伊金霍洛旗| 布尔津县| 元氏县| 宜昌市| 八宿县| 依兰县| 镇平县| 锦屏县| 金昌市| 鲁甸县| 阿拉善右旗| 西城区| 大方县| 日照市| 江川县| 万安县| 璧山县| 永城市| 喀什市| 新乡市| 贡嘎县| 定日县| 延川县| 阿拉善左旗| 乐陵市| 石屏县| 四会市| 招远市| 灵璧县| 龙南县| 昂仁县| 泸西县| 同心县| 平遥县| 延吉市| 南溪县| 福贡县|