Hey sry das ich nochmal frage ich glabe ich hab alles richtig gemacht mit dem ToString. Zu mindestens stürzt das Programm nicht mehr ab
jetzt übernimmt meine Datagrieview jedoch die Änderungen nicht und ich weiß nicht warum ich kann zwar den btnEdit drücken jedoch passiert nichts ??
Hier die Hinzu
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Hinzu : Form
{
public Auftrag Auf { get; set; }
public Hinzu()
{
InitializeComponent();
}
private void Hinzu_Load(object sender, EventArgs e)
{
if(Auf != null)
{
textBoxBezeichnung.Text = Auf.Bezeichnung;
textBoxAbgabe.Text = Auf.Abgabe;
textBoxAuftraggeber.Text = Auf.Auftraggeber;
string Preis = Auf.preis.ToString();
textBoxBetrag.Text = Preis;
string Menge = Auf.Menge.ToString();
textBoxMenge.Text = Menge;
}
}
public void btnSave_Click(object sender, EventArgs e)
{
Auf.Bezeichnung = textBoxBezeichnung.Text;
double textBoxValue = double.Parse(textBoxBetrag.Text);
double textBoxM = double.Parse(textBoxMenge.Text);
Auf.Menge = textBoxM;
Auf.preis = textBoxValue;
Auf.Brutto = Auf.Menge * Auf.preis;
Auf.Netto = Auf.Brutto/119;
Auf.Netto *= 100;
Auf.Abgabe = textBoxAbgabe.Text;
Auf.Auftraggeber = textBoxAuftraggeber.Text;
Auf.AktDatum = System.DateTime.Now.ToShortDateString();
}
private void textBoxBetrag_TextChanged(object sender, EventArgs e)
{
}
private void textBoxBetrag_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;
if (ch == 44 && textBoxBetrag.Text.IndexOf(',') != -1)
{
e.Handled = true;
return;
}
if (!char.IsDigit(ch) && ch != 8 && ch != 44)
{
e.Handled = true;
}
}
und die Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCheckBoxCell ch1 = new DataGridViewCheckBoxCell();
if (ch1.Value == null)
ch1.Value = false;
switch (ch1.Value.ToString())
{
case "True":
ch1.Value = false;
break;
case "False":
ch1.Value = true;
break;
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
using (Hinzu hin = new Hinzu() { Auf = new Auftrag() })
{
if (hin.ShowDialog() == DialogResult.OK)
{
auftragBindingSource.Add(hin.Auf);
}
}
}
private void button4_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnEdit_Click(object sender, EventArgs e)
{
Auftrag edit = auftragBindingSource.Current as Auftrag;
if (edit != null)
{
using (Hinzu hin = new Hinzu() { Auf = edit })
{
if(hin.ShowDialog() == DialogResult.OK)
{
auftragBindingSource.EndEdit();
btnEdit.Focus();
}
}
}
}
}
}