vb中datagird控件怎样设置列宽
PrivateSubCommand2_Click()'查询'OnErrorResumeNextconStr="Provider=Microsoft.Jet.OLEDB.4...
Private Sub Command2_Click() '查询
'On Error Resume Next
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = D:\Access2003\Access2003\db1.mdb"
Set rs = Nothing
Conn.Open conStr
rs.CursorLocation = adUseClient
Sql = "DELETE late1.班级, * From late WHERE (((late.班级) Is Null)) or (((late.座号) Is Null))"
Conn.Execute Sql
Sql = " SELECT * from late1 order by 编号"
Conn.Execute Sql
rs.Open Sql, conStr, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
Conn.Close
End Sub datagird显示出来的列宽总是默认那么大 后面的列都看不到 要手动拖动 在控件上点编辑 手动设置好列宽 仍然没用 怎样用绑定的方法 设置列宽... 不用自动设置 手动设置大小也可以 展开
'On Error Resume Next
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = D:\Access2003\Access2003\db1.mdb"
Set rs = Nothing
Conn.Open conStr
rs.CursorLocation = adUseClient
Sql = "DELETE late1.班级, * From late WHERE (((late.班级) Is Null)) or (((late.座号) Is Null))"
Conn.Execute Sql
Sql = " SELECT * from late1 order by 编号"
Conn.Execute Sql
rs.Open Sql, conStr, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
Conn.Close
End Sub datagird显示出来的列宽总是默认那么大 后面的列都看不到 要手动拖动 在控件上点编辑 手动设置好列宽 仍然没用 怎样用绑定的方法 设置列宽... 不用自动设置 手动设置大小也可以 展开
2014-01-07
展开全部
你可以在该窗体的unload事件中,把datagrid控件的各个列宽存入一个ini文件或者注册表中,再在load事件中把列宽读出来即可。下面的例子是采用读写注册表的:
Private Sub Form_Load()
For i = 0 To DataGrid1.Columns.Count - 1
j = Val(GetSetting("MyApp", "ColWidth", CStr(i), "0"))
If j > 0 Then DataGrid1.Columns(i).Width = j
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
For i = 0 To DataGrid1.Columns.Count - 1
SaveSetting "MyApp", "ColWidth", CStr(i), DataGrid1.Columns(i).Width
Next
End Sub
Private Sub Form_Load()
For i = 0 To DataGrid1.Columns.Count - 1
j = Val(GetSetting("MyApp", "ColWidth", CStr(i), "0"))
If j > 0 Then DataGrid1.Columns(i).Width = j
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
For i = 0 To DataGrid1.Columns.Count - 1
SaveSetting "MyApp", "ColWidth", CStr(i), DataGrid1.Columns(i).Width
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询