以下是我用来创建未绑定数据网格视图的代码
Private Sub Initilaize_grid() Dim Itemcode As New DataGridViewColumn Dim desp As New DataGridViewColumn Dim type As New DataGridViewColumn Dim batch_no As New DataGridViewColumn Dim expiry_date As New DataGridViewColumn Dim qty As New DataGridViewColumn Dim unit_price As New DataGridViewColumn Dim disc as New DataGridViewColumn将 Grossamt 调暗为新的 DataGridViewColumn 将 disc_p 调暗为新的 DataGridViewColumn 将 netamt 调暗为新的 DataGridViewColumn
With Itemcode
.Name = "Itemcode"
.ValueType = GetType(String)
.HeaderText = "ITEM CODE"
.Width = 150
.CellTemplate = New DataGridViewTextBoxCell
End With
With desp
.Name = "desc"
.ValueType = GetType(String)
.HeaderText = "Description"
.Width = 250
.CellTemplate = New DataGridViewTextBoxCell
End With
With type
.Name = "type"
.ValueType = GetType(String)
.HeaderText = "Type"
.Width = 50
.CellTemplate = New DataGridViewTextBoxCell
End With
With uom
.Name = "uom"
.ValueType = GetType(String)
.HeaderText = "UOM"
.Width = 60
.CellTemplate = New DataGridViewTextBoxCell
End With
With batch_no
.Name = "batch"
.ValueType = GetType(String)
.HeaderText = "Batch"
.Width = 77
.CellTemplate = New DataGridViewTextBoxCell
End With
With expiry_date
.Name = "expiry"
.ValueType = GetType(Date)
.DefaultCellStyle.Format = "dd/MM/yyyy"
.HeaderText = "Expiry"
.Width = 70
.CellTemplate = New DataGridViewTextBoxCell
End With
With qty
.Name = "qty"
.ValueType = GetType(Integer)
.HeaderText = "Qty"
.Width = 70
.CellTemplate = New DataGridViewTextBoxCell
End With
With unit_price
.Name = "unitp"
.ValueType = GetType(Double)
.HeaderText = "Unit Price"
.Width = 70
.CellTemplate = New DataGridViewTextBoxCell
End With
With disc
.Name = "disc"
.ValueType = GetType(Double)
.HeaderText = "Discount"
.Width = 70
.CellTemplate = New DataGridViewTextBoxCell
End With
With disc_p
.Name = "discp"
.ValueType = GetType(Double)
.HeaderText = "Disc(%)"
.Width = 70
.CellTemplate = New DataGridViewTextBoxCell
End With
With grossamt
.Name = "gamt"
.ValueType = GetType(Double)
.HeaderText = "Gross Amount"
.Width = 70
.CellTemplate = New DataGridViewTextBoxCell
End With
With netamt
.Name = "namt"
.ValueType = GetType(Double)
.HeaderText = "Net Amount"
.Width = 125
.CellTemplate = New DataGridViewTextBoxCell
End With
With dgitemlist
.Columns.Add(Itemcode)
.Columns.Add(desp)
.Columns.Add(type)
.Columns.Add(uom)
.Columns.Add(batch_no)
.Columns.Add(expiry_date)
.Columns.Add(qty)
.Columns.Add(unit_price)
.Columns.Add(grossamt)
.Columns.Add(disc_p)
.Columns.Add(disc)
.Columns.Add(netamt)
End With
End Sub
当我在到期列中输入日期时出现以下错误..我输入日期为 mmddyyyy..即使 yyyymmdd 格式也会给出附加错误,因为字符串未被识别为有效的日期时间..