datagrid 问题

Rossetti 2003-05-17 11:46:25
如何改变datagrid中列的宽度。(事例)
TableStyles如何用?
GridColumnStyles如何用?
谢谢!
...全文
20 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Montaque 2003-05-17
  • 打赏
  • 举报
回复
下面的示例集创建两个 DataGridTableStyle 实例,并将每个对象的 MappingName 设置为 DataSet 中一个 DataTable 的 TableName。示例随后将 DataGridColumnStyle 对象添加到每个 DataGridTableStyle 对象的 GridColumnStylesCollection 中。

[Visual Basic]
Private Sub AddCustomDataTableStyle()
' Create a new DataGridTableStyle and set
' its MappingName to the TableName of a DataTable.
Dim ts1 As New DataGridTableStyle()
ts1.MappingName = "Customers"

' Add a GridColumnStyle and set its MappingName
' to the name of a DataColumn in the DataTable.
' Set the HeaderText and Width properties.

Dim boolCol As New DataGridBoolColumn()
boolCol.MappingName = "Current"
boolCol.HeaderText = "IsCurrent Customer"
boolCol.Width = 150
ts1.GridColumnStyles.Add(boolCol)

' Add a second column style.
Dim TextCol As New DataGridTextBoxColumn()
TextCol.MappingName = "custName"
TextCol.HeaderText = "Customer Name"
TextCol.Width = 250
ts1.GridColumnStyles.Add(TextCol)

' Create the second table style with columns.
Dim ts2 As New DataGridTableStyle()
ts2.MappingName = "Orders"

' Change the colors.
ts2.ForeColor = Color.Yellow
ts2.AlternatingBackColor = Color.Blue
ts2.BackColor = Color.Blue

' Create new DataGridColumnStyle objects.
Dim cOrderDate As New DataGridTextBoxColumn()
cOrderDate.MappingName = "OrderDate"
cOrderDate.HeaderText = "Order Date"
cOrderDate.Width = 100
ts2.GridColumnStyles.Add(cOrderDate)

Dim pcol As PropertyDescriptorCollection = Me.BindingContext(myDataSet, "Customers.custToOrders").GetItemProperties()

Dim csOrderAmount As New DataGridTextBoxColumn(pcol("OrderAmount"), "c", True)
csOrderAmount.MappingName = "OrderAmount"
csOrderAmount.HeaderText = "Total"
csOrderAmount.Width = 100
ts2.GridColumnStyles.Add(csOrderAmount)

' Add the DataGridTableStyle objects to the collection.
myDataGrid.TableStyles.Add(ts1)
myDataGrid.TableStyles.Add(ts2)
End Sub 'AddCustomDataTableStyle
fly_miss 2003-05-17
  • 打赏
  • 举报
回复
可以在Datagrid中设置,mappname分别对应表名和列名

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧