以下是我用来创建未绑定的datagridview
的代码Private Sub Initilaize_grid() Dim Itemcode As New DataGridViewColumn Dim desp As New DataGridViewColumn Dim type As New DataGridViewColumn Dim uom 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 Dim grossamt As New DataGridViewColumn Dim disc_p As New DataGridViewColumn Dim netamt As New 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..even yyyymmdd格式给出附加的错误,因为字符串未被识别为有效的日期时间..
答案 0 :(得分:0)
您提供的DefaultCellStyle.Format仅用于输出。不是为了解析你的输入。猜你必须根据windows系统的本地化设置输入你的日期(包括日期部分之间的斜线或点)