Predmet:Re: Kako sprečiti dupli unos u DataGrid (dupli proizvod)
1. - visual studio 2017
2. -
3. - bound DataGrid
**************
Public Class Form1
Private Sub PorudzbineBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles PorudzbineBindingNavigatorSaveItem.Click
Me.Validate()
Me.PorudzbineBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Porudzbine_DataSet)
Me.PorudzbineDetaljiTableAdapter.Update(Me.Porudzbine_DataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Porudzbine_DataSet.PorudzbineDetalji' table. You can move, or remove it, as needed.
Me.PorudzbineDetaljiTableAdapter.Fill(Me.Porudzbine_DataSet.PorudzbineDetalji)
'TODO: This line of code loads data into the 'Porudzbine_DataSet.Relacije' table. You can move, or remove it, as needed.
Me.RelacijeTableAdapter.Fill(Me.Porudzbine_DataSet.Relacije)
'TODO: This line of code loads data into the 'Porudzbine_DataSet.Kupci' table. You can move, or remove it, as needed.
Me.KupciTableAdapter.Fill(Me.Porudzbine_DataSet.Kupci)
'TODO: This line of code loads data into the 'Porudzbine_DataSet.Porudzbine' table. You can move, or remove it, as needed.
Me.PorudzbineTableAdapter.Fill(Me.Porudzbine_DataSet.Porudzbine)
CustomDataGridView1.Columns(4).DefaultCellStyle.Format = "N2"
CustomDataGridView1.Columns(5).DefaultCellStyle.Format = "N2"
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Enter Then
Me.SelectNextControl(Me.ActiveControl, True, True, True, False) 'for Select Next Control
End If
End Sub
Private Sub NazivComboBox_LostFocus(sender As Object, e As EventArgs) Handles NazivComboBox.LostFocus
Dim naziv_dm As New Porudzbine_DataSetTableAdapters.KupciTableAdapter
KupacIDTextBox.Text = naziv_dm.id_dm_ScalarQuery(NazivComboBox.Text)
End Sub
Private Sub CustomDataGridView1_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles CustomDataGridView1.DataError
Dim view As DataGridView = CType(sender, DataGridView)
'view.Rows(e.RowIndex).Cells(e.ColumnIndex).ErrorText = "an error"
'e.ThrowException = False
End Sub
Private Sub CustomDataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles CustomDataGridView1.CellEndEdit
'MessageBox.Show(CustomDataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString())
Dim proizvod_info As New Porudzbine_DataSetTableAdapters.ProizvodiTableAdapter
'Dim ukupna_tezina As New Porudzbine_DataSetTableAdapters.PorudzbineDetaljiTableAdapter
If (e.ColumnIndex = 0) Then
If Val(CustomDataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) > 0 Then
CustomDataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = proizvod_info.naziv_proizvoda_ScalarQuery(CInt(Val(CustomDataGri
dView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)))
End If
End If
Dim UkupnaTezina As DataGridView = DirectCast(sender, DataGridView)
UkupnaTezina(5, e.RowIndex).Value = Math.Round(UkupnaTezina(2, e.RowIndex).Value * proizvod_info.TezinaProizvoda_ScalarQuery(UkupnaTezina(0, e.RowIndex).Value) + UkupnaTezina(3, e.RowIndex).Value * proizvod_info.BrojKomPak_ScalarQuery(UkupnaTezina(0, e.RowIndex).Value) * Convert.ToDouble(proizvod_info.TezinaProizvoda_ScalarQuery(UkupnaTezina(0, e.RowIndex).Value)) + proizvod_info.TezinaProizvoda_ScalarQuery(UkupnaTezina(0, e.RowIndex).Value) * Math.Round((Convert.ToDouble(UkupnaTezina(4, e.RowIndex).Value) / Convert.ToDouble(proizvod_info.TezinaProizvoda_ScalarQuery(UkupnaTezina(0, e.RowIndex).Value)))), 2)
If IsDBNull(UkupnaTezina(0, e.RowIndex).Value) Then Exit Sub
' If CustomDataGridView1.RowCount > 1 Then
' Dim amount As Decimal = 0
' For index As Integer = 0 To CustomDataGridView1.RowCount - 1
' amount += Convert.ToDecimal(CustomDataGridView1.Rows(index).Cells(5).Value)
' Next
' TextBox1.Text = Val(amount)
' End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BindingNavigatorAddNewItem.PerformClick()
Me.NazivComboBox.Select()
End Sub
End Class