Hallo,
ich habe hier folgende Tabelle im typisiertem Dataset (s. Anhang).
Die Tabelle ist an ein DGV gebunden. Der User kann über die Oberfläche verschiedene Bestellungen hinzufügen. Alle Werte sind ReadOnly im DGV, außer Anzahl. Dafür habe ich mir aus dem Netz eine NumericUpDownColumn gezogen. Ändert der User also die Anzahl, soll in der Spalte GPreis der komplette Preis stehen (also Preis * Anzahl). Das funktioniert aber nicht. Ändern tut sich rein garnichts. Erhöhe ich per Code die Anzahl um +1, wenn der User das selbe nochmal bestellt, dann funktioniert alles tadellos. Das möchte ich so aber nicht.
Vllt hilft der Code des NumericUpDown.
Spoiler anzeigen
Das ist mein erstes Projekt mit typisierten Datasets, entschuldigt also wenn ich einfach einen Denkfehler habe
Ich bin für jede Hilfe Dankbar.
Edit: Er scheint es zu berechnen, wenn eine neue Bestellung hinzugefügt wird. Bringt mir auch nicht viel, besonders dann, wenn der User keine weitere Bestellung vornimmt. Dann stimmt die Spalte dennoch nicht...
*Topic verschoben*
ich habe hier folgende Tabelle im typisiertem Dataset (s. Anhang).
Die Tabelle ist an ein DGV gebunden. Der User kann über die Oberfläche verschiedene Bestellungen hinzufügen. Alle Werte sind ReadOnly im DGV, außer Anzahl. Dafür habe ich mir aus dem Netz eine NumericUpDownColumn gezogen. Ändert der User also die Anzahl, soll in der Spalte GPreis der komplette Preis stehen (also Preis * Anzahl). Das funktioniert aber nicht. Ändern tut sich rein garnichts. Erhöhe ich per Code die Anzahl um +1, wenn der User das selbe nochmal bestellt, dann funktioniert alles tadellos. Das möchte ich so aber nicht.
Vllt hilft der Code des NumericUpDown.
VB.NET-Quellcode
- Public Class NumericUpDownColumn
- Inherits DataGridViewColumn
- Public Sub New()
- MyBase.New(New NumericUpDownCell())
- End Sub
- Public Overrides Property CellTemplate() As DataGridViewCell
- Get
- Return MyBase.CellTemplate
- End Get
- Set(ByVal value As DataGridViewCell)
- ' Ensure that the cell used for the template is a CalendarCell.
- If Not (value Is Nothing) AndAlso Not value.GetType().IsAssignableFrom(GetType(NumericUpDownCell)) Then
- Throw New InvalidCastException("Must be a CalendarCell")
- End If
- MyBase.CellTemplate = value
- End Set
- End Property
- End Class
- Public Class NumericUpDownCell
- Inherits DataGridViewTextBoxCell
- Public Sub New()
- ' Use the short date format.
- Me.Style.Format = "#.##"
- End Sub
- Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)
- ' Set the value of the editing control to the current cell value.
- MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
- Dim ctl As NumericUpDownEditingControl = CType(DataGridView.EditingControl, NumericUpDownEditingControl)
- If Me.Value.Equals(DBNull.Value) Then
- ctl.Value = 0
- Else
- ctl.Value = CType(Me.Value, Decimal)
- End If
- End Sub
- Public Overrides ReadOnly Property EditType() As Type
- Get
- ' Return the type of the editing contol that CalendarCell uses.
- Return GetType(NumericUpDownEditingControl)
- End Get
- End Property
- Public Overrides ReadOnly Property ValueType() As Type
- Get
- ' Return the type of the value that CalendarCell contains.
- Return GetType(Decimal)
- End Get
- End Property
- Public Overrides ReadOnly Property DefaultNewRowValue() As Object
- Get
- ' Use the current date and time as the default value.
- Return 0
- End Get
- End Property
- End Class
- Class NumericUpDownEditingControl
- Inherits NumericUpDown
- Implements IDataGridViewEditingControl
- Private dataGridViewControl As DataGridView
- Private valueIsChanged As Boolean = False
- Private rowIndexNum As Integer
- Public Sub New()
- Me.DecimalPlaces = 2
- End Sub
- Public Property EditingControlFormattedValue() As Object Implements IDataGridViewEditingControl.EditingControlFormattedValue
- Get
- Return Me.Value.ToString("#.##")
- End Get
- Set(ByVal value As Object)
- If TypeOf value Is Decimal Then
- Me.Value = Decimal.Parse(value.ToString)
- End If
- End Set
- End Property
- Public Function GetEditingControlFormattedValue(ByVal context As DataGridViewDataErrorContexts) As Object Implements IDataGridViewEditingControl.GetEditingControlFormattedValue
- Return Me.Value.ToString("#.##")
- End Function
- Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As DataGridViewCellStyle) Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl
- Me.Font = dataGridViewCellStyle.Font
- Me.ForeColor = dataGridViewCellStyle.ForeColor
- Me.BackColor = dataGridViewCellStyle.BackColor
- End Sub
- Public Property EditingControlRowIndex() As Integer Implements IDataGridViewEditingControl.EditingControlRowIndex
- Get
- Return rowIndexNum
- End Get
- Set(ByVal value As Integer)
- rowIndexNum = value
- End Set
- End Property
- Public Function EditingControlWantsInputKey(ByVal key As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean Implements IDataGridViewEditingControl.EditingControlWantsInputKey
- ' Let the DateTimePicker handle the keys listed.
- Select Case key And Keys.KeyCode
- Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp
- Return True
- Case Else
- Return False
- End Select
- End Function
- Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements IDataGridViewEditingControl.PrepareEditingControlForEdit
- ' No preparation needs to be done.
- End Sub
- Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements IDataGridViewEditingControl.RepositionEditingControlOnValueChange
- Get
- Return False
- End Get
- End Property
- Public Property EditingControlDataGridView() As DataGridView Implements IDataGridViewEditingControl.EditingControlDataGridView
- Get
- Return dataGridViewControl
- End Get
- Set(ByVal value As DataGridView)
- dataGridViewControl = value
- End Set
- End Property
- Public Property EditingControlValueChanged() As Boolean Implements IDataGridViewEditingControl.EditingControlValueChanged
- Get
- Return valueIsChanged
- End Get
- Set(ByVal value As Boolean)
- valueIsChanged = value
- End Set
- End Property
- Public ReadOnly Property EditingControlCursor() As Cursor Implements IDataGridViewEditingControl.EditingPanelCursor
- Get
- Return MyBase.Cursor
- End Get
- End Property
- Protected Overrides Sub OnValueChanged(ByVal eventargs As EventArgs)
- ' Notify the DataGridView that the contents of the cell have changed.
- valueIsChanged = True
- Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
- MyBase.OnValueChanged(eventargs)
- End Sub
- End Class
Das ist mein erstes Projekt mit typisierten Datasets, entschuldigt also wenn ich einfach einen Denkfehler habe
Ich bin für jede Hilfe Dankbar.
Edit: Er scheint es zu berechnen, wenn eine neue Bestellung hinzugefügt wird. Bringt mir auch nicht viel, besonders dann, wenn der User keine weitere Bestellung vornimmt. Dann stimmt die Spalte dennoch nicht...
*Topic verschoben*
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Marcus Gräfe“ ()