1 个解决方案
#1
首先得为datagrid添加TableStyle
Private Sub AddDataTableStyle()
Dim ts1 As DataGridTableStyle
ts1 = New DataGridTableStyle()
ts1.MappingName = "Customers"
Dim TextCol As DataGridTextBoxColumn
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custID"
TextCol.HeaderText = "客户编号"
TextCol.Width = 100
TextCol.NullText=""
ts1.GridColumnStyles.Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custName"
TextCol.HeaderText = "客户名称"
TextCol.Width = 100
TextCol.NullText=""
ts1.GridColumnStyles.Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "num"
TextCol.HeaderText = "数量" '///假设这列是大数字字段
TextCol.Width = 100
TextCol.NullText=""
TextCol.Format="g" '///这里对该列格式化
ts1.GridColumnStyles.Add(TextCol)
dataGrid1.TableStyles.Add(ts1)
End Sub
你也可以在窗体设计器中设置
Private Sub AddDataTableStyle()
Dim ts1 As DataGridTableStyle
ts1 = New DataGridTableStyle()
ts1.MappingName = "Customers"
Dim TextCol As DataGridTextBoxColumn
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custID"
TextCol.HeaderText = "客户编号"
TextCol.Width = 100
TextCol.NullText=""
ts1.GridColumnStyles.Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custName"
TextCol.HeaderText = "客户名称"
TextCol.Width = 100
TextCol.NullText=""
ts1.GridColumnStyles.Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "num"
TextCol.HeaderText = "数量" '///假设这列是大数字字段
TextCol.Width = 100
TextCol.NullText=""
TextCol.Format="g" '///这里对该列格式化
ts1.GridColumnStyles.Add(TextCol)
dataGrid1.TableStyles.Add(ts1)
End Sub
你也可以在窗体设计器中设置
#1
首先得为datagrid添加TableStyle
Private Sub AddDataTableStyle()
Dim ts1 As DataGridTableStyle
ts1 = New DataGridTableStyle()
ts1.MappingName = "Customers"
Dim TextCol As DataGridTextBoxColumn
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custID"
TextCol.HeaderText = "客户编号"
TextCol.Width = 100
TextCol.NullText=""
ts1.GridColumnStyles.Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custName"
TextCol.HeaderText = "客户名称"
TextCol.Width = 100
TextCol.NullText=""
ts1.GridColumnStyles.Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "num"
TextCol.HeaderText = "数量" '///假设这列是大数字字段
TextCol.Width = 100
TextCol.NullText=""
TextCol.Format="g" '///这里对该列格式化
ts1.GridColumnStyles.Add(TextCol)
dataGrid1.TableStyles.Add(ts1)
End Sub
你也可以在窗体设计器中设置
Private Sub AddDataTableStyle()
Dim ts1 As DataGridTableStyle
ts1 = New DataGridTableStyle()
ts1.MappingName = "Customers"
Dim TextCol As DataGridTextBoxColumn
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custID"
TextCol.HeaderText = "客户编号"
TextCol.Width = 100
TextCol.NullText=""
ts1.GridColumnStyles.Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custName"
TextCol.HeaderText = "客户名称"
TextCol.Width = 100
TextCol.NullText=""
ts1.GridColumnStyles.Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "num"
TextCol.HeaderText = "数量" '///假设这列是大数字字段
TextCol.Width = 100
TextCol.NullText=""
TextCol.Format="g" '///这里对该列格式化
ts1.GridColumnStyles.Add(TextCol)
dataGrid1.TableStyles.Add(ts1)
End Sub
你也可以在窗体设计器中设置