台灣最大程式設計社群網站
線上人數
1656
 
會員總數:240858
討論主題:186640
歡迎您免費加入會員
討論區列表 >> VB.NET >> 用DataGridView的時候輸入一個數字會出現兩個
[ 變換順序 ]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
用DataGridView的時候輸入一個數字會出現兩個
價值 : 30 QP  點閱數:179 回應數:3

樓主

陳八七
初學者
11 3
83 11
發送站內信

各位大大好:
我用DataGridView控制項新增資料的時候
輸入一個數字(5)變成兩個數字(55)了!!
要怎麼解決?

搜尋相關Tags的文章: [ DataGridView ] , [ 資料 ] ,
本篇文章發表於2017-07-19 22:48
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
回應

小魚
檢舉此回應
這不一定是DataGridView的問題,
你的程式碼可以貼上來看看嗎?
本篇文章回覆於2017-07-20 11:58
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
作者回應

陳八七
檢舉此回應
全部都在這了:
Public Class fmDelivery
Dim Data As New ASTERFunction
Dim WithEvents MyBS As New BindingSource
Dim er As Boolean = False
Private Sub SetDataGridView()
Dim Grid = DataGridView1
Grid.Columns(0).HeaderText = "出貨日期"
Grid.Columns(1).HeaderText = "進價"
Grid.Columns(1).Width = 70
Grid.Columns(2).HeaderText = "機器名稱"
Grid.Columns(2).Width = 150
Grid.Columns(3).HeaderText = "數量"
Grid.Columns(3).Width = 80
Grid.Columns(4).HeaderText = "客戶簡稱"
Grid.Columns(4).ContextMenuStrip = Me.ContextMenuStrip1
Grid.Columns(4).Width = 150
Grid.Columns(5).HeaderText = "出價"
Grid.Columns(6).HeaderText = "送貨"
Grid.Columns(6).Width = 50
Grid.Columns(7).HeaderText = "發票"
Grid.Columns(7).Width = 50
Grid.Columns(8).HeaderText = "貨款"
Grid.Columns(8).Width = 70
Grid.Columns(9).HeaderText = "客款"
Grid.Columns(9).Width = 60
Grid.Columns(10).HeaderText = "備註"
Grid.Columns(10).Width = 150
End Sub
Private Sub fmDelivery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Data.MyBindingSource = MyBS
Data.MyDataSet = New DataSet("ASTERData")
Data.CreateTables()
Data.LoadData()
Data.MyBindingSource.DataSource = Data.MyDataSet.Tables("Delivery")
DataGridView1.DataSource = Data.MyBindingSource
SetDataGridView()

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Data.MyDataSet.Tables("Delivery").BeginLoadData()
Try
Me.Validate()
MyBS.EndEdit()
Data.MyDataSet.WriteXml("D:\Data\ASTERData.xml", XmlWriteMode.IgnoreSchema)
Catch ex As Exception
Data.MyDataSet.Tables("Delivery").RejectChanges()
MessageBox.Show(ex.Message, "更新錯誤", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Exit Sub
End Try
Data.MyDataSet.Tables("Delivery").AcceptChanges()
Data.MyDataSet.Tables("Delivery").EndLoadData()

End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

MyBS.CancelEdit()
DataGridView1.CancelEdit()
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim msgResult = MessageBox.Show("是否要刪除目前的資料?", "刪除", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Select Case msgResult
Case Windows.Forms.DialogResult.Yes
Try
MyBS.RemoveCurrent()
Catch ex As Exception
MessageBox.Show(ex.Message, "刪除錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Case Windows.Forms.DialogResult.No
Exit Sub
Case Windows.Forms.DialogResult.None
Exit Sub
End Select

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click



MyBS.AddNew()
DataGridView1.Rows(MyBS.Position).Cells(0).Value = Today.ToString("yyyy/MM/dd")
DataGridView1.Rows(MyBS.Position).Cells(1).Value = "庫存"
DataGridView1.Rows(MyBS.Position).Cells(8).Value = "庫存"
DataGridView1.Rows(MyBS.Position).Cells(9).Value = "到付"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
MyBS.MoveLast()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MyBS.MoveNext()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MyBS.MovePrevious()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MyBS.MoveFirst()

End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
MyBS.Filter = "CustomerAttribName Like '%" & TextBox1.Text & "%'"
SetDataGridView()

End Sub

Private Sub 查詢客戶簡稱ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 查詢客戶簡稱ToolStripMenuItem.Click
Dim TS As New CheckCustomer
DataGridView1.Rows(MyBS.Position).Cells(4).Value = TS.CustomerID
DataGridView1.Rows(MyBS.Position).Cells(4).Selected = True
End Sub

Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
Dim ErrorMsg As String
ErrorMsg = "在銷售管理上輸入了不合法的資料導致錯誤:" & vbCrLf & vbCrLf & _
"第" & (e.ColumnIndex + 1).ToString & "個欄位" & vbCrLf & "第" & CInt(e.RowIndex + 1).ToString + "筆紀錄" & _
vbCrLf & vbCrLf & "系統錯誤訊息:" & vbCrLf & vbCrLf & e.Exception.ToString & vbCrLf & vbCrLf & _
"請按Esc鍵或取消銷售管理的編輯或輸入一個正確且合法的資料"
MsgBox(ErrorMsg, MsgBoxStyle.Exclamation, "資料輸入錯誤")
End Sub

Private Sub DataGridView1_DefaultValuesNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles DataGridView1.DefaultValuesNeeded

With e.Row
.Cells(0).Value = Today.ToString("yyyy/MM/dd")
.Cells(1).Value = "庫存"
.Cells(8).Value = "庫存"
.Cells(9).Value = "到付"
End With

End Sub

End Class
本篇文章回覆於2017-07-20 12:51
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
3樓
回應

P陳
檢舉此回應
加上這個指令就好了
datagridview1.editmode=EditOnEnter
本篇文章回覆於2017-07-29 19:47
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
[ 變換順序 ]   
1

回覆
如要回應,請先登入.