主题:vb.net中怎样修改控件datagrid每列的宽度?
大家好!
最近碰到一个麻烦,我用vb.net的设计界面时,控件datagrid显示的数据不能完全显示,所以需要改变每列的宽度。我原来是这样做的,请大家指点指点。
Private Sub ShowDataToGrid()
Dim Bloom_DataTable As DataTable = New DataTable("Bloom_DataTable")
Dim Bloom_DataSet As New DataSet
Dim MyDataRow As DataRow
Creat_Table(Bloom_DataTable)
OCusers = New Cusers
OCusers.Requery(OCusers)
Dim i As Integer = OCusers.Count
For Each OCuser In OCusers
MyDataRow = Bloom_DataTable.NewRow
MyDataRow("用户编号") = OCuser.log_code
MyDataRow("用户名称") = OCuser.user_name
MyDataRow("用户等级") = OCuser.user_level
MyDataRow("用户简介") = OCuser.user_description
MyDataRow("所属班组") = OCuser.belong_group
Bloom_DataTable.Rows.Add(MyDataRow)
Next
Bloom_DataSet.Tables.Add(Bloom_DataTable)
Grd_primarydata.SetDataBinding(Bloom_DataSet, "Bloom_DataTable")
end sub
Private Sub Creat_Table(ByVal mydatatable As DataTable)
Dim myDataColumn As DataColumn
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "用户编号"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "用户名称"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.Int32")
myDataColumn.ColumnName = "用户等级"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "用户简介"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "所属班组"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
End Sub
但在过程Creat_Table中不能修改myDataColumn的宽度
于是采用对datagrid的tablestyles属性设置,gridcolumnstyles都已设置好标题和宽度,为什么运行连每列的标题都不显示,是不是还要在程序中添加代码处理???
特来请教大家,谢谢!!!
最近碰到一个麻烦,我用vb.net的设计界面时,控件datagrid显示的数据不能完全显示,所以需要改变每列的宽度。我原来是这样做的,请大家指点指点。
Private Sub ShowDataToGrid()
Dim Bloom_DataTable As DataTable = New DataTable("Bloom_DataTable")
Dim Bloom_DataSet As New DataSet
Dim MyDataRow As DataRow
Creat_Table(Bloom_DataTable)
OCusers = New Cusers
OCusers.Requery(OCusers)
Dim i As Integer = OCusers.Count
For Each OCuser In OCusers
MyDataRow = Bloom_DataTable.NewRow
MyDataRow("用户编号") = OCuser.log_code
MyDataRow("用户名称") = OCuser.user_name
MyDataRow("用户等级") = OCuser.user_level
MyDataRow("用户简介") = OCuser.user_description
MyDataRow("所属班组") = OCuser.belong_group
Bloom_DataTable.Rows.Add(MyDataRow)
Next
Bloom_DataSet.Tables.Add(Bloom_DataTable)
Grd_primarydata.SetDataBinding(Bloom_DataSet, "Bloom_DataTable")
end sub
Private Sub Creat_Table(ByVal mydatatable As DataTable)
Dim myDataColumn As DataColumn
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "用户编号"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "用户名称"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.Int32")
myDataColumn.ColumnName = "用户等级"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "用户简介"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "所属班组"
myDataColumn.ReadOnly = True
mydatatable.Columns.Add(myDataColumn)
End Sub
但在过程Creat_Table中不能修改myDataColumn的宽度
于是采用对datagrid的tablestyles属性设置,gridcolumnstyles都已设置好标题和宽度,为什么运行连每列的标题都不显示,是不是还要在程序中添加代码处理???
特来请教大家,谢谢!!!