sub bindthedata()
dim objconn as oledbconnection
dim objcmd as oledbcommand
objconn = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" _
+ server.mappath("test.mdb"))
dim strsql as string
strsql = "select top 10 id,title,createdate from document"
objcmd = new oledbcommand(strsql, objconn)
objconn.open()
dtgcusts.datasource = objcmd.executereader()
dtgcusts.databind()
objconn.close()
objconn.dispose()
end sub
sub showdetails(byval sender as system.object, byval e as system.eventargs)
dim intcounter as integer
for intcounter = 1 to dtgcusts.columns.count - 1
dtgcusts.columns(intcounter).visible = true
next
end sub
sub hidedetails(byval sender as system.object, byval e as system.eventargs)
dim intcounter as integer
for intcounter = 1 to dtgcusts.columns.count - 1
dtgcusts.columns(intcounter).visible = false
next
end sub
end class
主 题: 请教在datagridview中怎样生成自适应的列宽?
你可以用下面的方法实现:
private void gridview1_mousemove(object sender, system.windows.forms.mouseeventargs e)
{
int a=e.x/colkeywords.width;
int b=(e.y+10)/colkeywords.width-3;
if(a>=0 && b>=0 && a<dataset11.tables["bugman"].columns.count && b<dataset11.tables["bugman"].rows.count)
tooltipcontroller1.settooltip(gridcontrol1,dataset11.tables["bugman"].rows[b].itemarray[a].tostring());
}
我用的是tooltip,colkeywords.width是某一个列的长度