Hi
Ich bin noch etwas neu in diesem .Net kram und auch im Forum 🙂 aber es gibt ja keine dummen fragen und verbessert mich wenn ich was nicht richtig mache .
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace LanStat
{
/// <summary>
/// Zusammenfassung für Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
DataSet dsDaten = new DataSet("Test");
string Path = "C:\\Daten.xml";
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TabPage tabPage3;
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.DateTimePicker dpGebdatum;
public ArrayList PersonenArray = new ArrayList();
private System.Windows.Forms.TextBox tbClan;
private System.Windows.Forms.TextBox tbProzent;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button bEntfernen;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.ListBox lbGames;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tbLoses;
private System.Windows.Forms.TextBox tbSiege;
private System.Windows.Forms.Button bPunkte;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox tbVorname;
private System.Windows.Forms.TextBox tbName;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.ListView lbPersonenListe;
private System.Windows.Forms.ColumnHeader colName;
private System.Windows.Forms.ColumnHeader colVorname;
private System.Windows.Forms.TextBox tbNick;
private System.Windows.Forms.Label Nick;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label9;
public int m_MaxIndex = 0;
public Form1()
{
//
// Erforderlich für die Windows Form-Designerunterstützung
//
InitializeComponent();
//
// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
//
if (File.Exists(Path))
{
dsDaten.ReadXml(Path, XmlReadMode.ReadSchema);
FillList();
}
else
{
DataTable dt = null;
dt = dsDaten.Tables.Add("Liste");
dt.Columns.Add("ID", typeof(long));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Vorname", typeof(string));
dt.Columns.Add("Clan", typeof(string));
dt.Columns.Add("Gebdatum", typeof(DateTime));
dt.Columns.Add("Nick", typeof(string));
dt.Columns.Add("Games", typeof(string));
dsDaten.WriteXml(Path, XmlWriteMode.WriteSchema);
}
}
/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.lbGames = new System.Windows.Forms.ListBox();
this.label2 = new System.Windows.Forms.Label();
this.tbClan = new System.Windows.Forms.TextBox();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.label9 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.Nick = new System.Windows.Forms.Label();
this.tbNick = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.tbLoses = new System.Windows.Forms.TextBox();
this.tbSiege = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.tbProzent = new System.Windows.Forms.TextBox();
this.dpGebdatum = new System.Windows.Forms.DateTimePicker();
this.tbVorname = new System.Windows.Forms.TextBox();
this.tbName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.bPunkte = new System.Windows.Forms.Button();
this.bEntfernen = new System.Windows.Forms.Button();
this.lbPersonenListe = new System.Windows.Forms.ListView();
this.colName = new System.Windows.Forms.ColumnHeader();
this.colVorname = new System.Windows.Forms.ColumnHeader();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(256, 48);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(120, 136);
this.pictureBox1.TabIndex = 4;
this.pictureBox1.TabStop = false;
//
// lbGames
//
this.lbGames.Location = new System.Drawing.Point(112, 312);
this.lbGames.Name = "lbGames";
this.lbGames.Size = new System.Drawing.Size(120, 82);
this.lbGames.TabIndex = 6;
this.lbGames.SelectedIndexChanged += new System.EventHandler(this.lbGames_SelectedIndexChanged);
//
// label2
//
this.label2.Location = new System.Drawing.Point(48, 312);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 16);
this.label2.TabIndex = 7;
this.label2.Text = "Games";
//
// tbClan
//
this.tbClan.Location = new System.Drawing.Point(128, 136);
this.tbClan.Name = "tbClan";
this.tbClan.Size = new System.Drawing.Size(104, 20);
this.tbClan.TabIndex = 9;
this.tbClan.Text = "";
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Location = new System.Drawing.Point(184, 8);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(664, 544);
this.tabControl1.TabIndex = 11;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.label9);
this.tabPage1.Controls.Add(this.textBox1);
this.tabPage1.Controls.Add(this.Nick);
this.tabPage1.Controls.Add(this.tbNick);
this.tabPage1.Controls.Add(this.label4);
this.tabPage1.Controls.Add(this.label3);
this.tabPage1.Controls.Add(this.tbLoses);
this.tabPage1.Controls.Add(this.tbSiege);
this.tabPage1.Controls.Add(this.label8);
this.tabPage1.Controls.Add(this.label7);
this.tabPage1.Controls.Add(this.label6);
this.tabPage1.Controls.Add(this.label5);
this.tabPage1.Controls.Add(this.tbProzent);
this.tabPage1.Controls.Add(this.dpGebdatum);
this.tabPage1.Controls.Add(this.tbVorname);
this.tabPage1.Controls.Add(this.tbName);
this.tabPage1.Controls.Add(this.lbGames);
this.tabPage1.Controls.Add(this.pictureBox1);
this.tabPage1.Controls.Add(this.tbClan);
this.tabPage1.Controls.Add(this.label2);
this.tabPage1.Controls.Add(this.label1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(656, 518);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.Click += new System.EventHandler(this.tabPage1_Click);
//
// label9
//
this.label9.Location = new System.Drawing.Point(304, 408);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(120, 16);
this.label9.TabIndex = 28;
this.label9.Text = "Rang";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(432, 408);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(120, 20);
this.textBox1.TabIndex = 27;
this.textBox1.Text = "";
//
// Nick
//
this.Nick.Location = new System.Drawing.Point(48, 168);
this.Nick.Name = "Nick";
this.Nick.Size = new System.Drawing.Size(72, 16);
this.Nick.TabIndex = 26;
this.Nick.Text = "Nick";
//
// tbNick
//
this.tbNick.Location = new System.Drawing.Point(128, 168);
this.tbNick.Name = "tbNick";
this.tbNick.Size = new System.Drawing.Size(104, 20);
this.tbNick.TabIndex = 25;
this.tbNick.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(304, 344);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(120, 16);
this.label4.TabIndex = 24;
this.label4.Text = "Loses gesamt";
//
// label3
//
this.label3.Location = new System.Drawing.Point(304, 312);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(120, 16);
this.label3.TabIndex = 23;
this.label3.Text = "Siege gesamt";
//
// tbLoses
//
this.tbLoses.Location = new System.Drawing.Point(432, 344);
this.tbLoses.Name = "tbLoses";
this.tbLoses.ReadOnly = true;
this.tbLoses.Size = new System.Drawing.Size(120, 20);
this.tbLoses.TabIndex = 21;
this.tbLoses.Text = "";
//
// tbSiege
//
this.tbSiege.Location = new System.Drawing.Point(432, 312);
this.tbSiege.Name = "tbSiege";
this.tbSiege.ReadOnly = true;
this.tbSiege.Size = new System.Drawing.Size(120, 20);
this.tbSiege.TabIndex = 22;
this.tbSiege.Text = "";
//
// label8
//
this.label8.Location = new System.Drawing.Point(48, 136);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(72, 16);
this.label8.TabIndex = 19;
this.label8.Text = "Clan";
//
// label7
//
this.label7.Location = new System.Drawing.Point(48, 104);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(72, 16);
this.label7.TabIndex = 18;
this.label7.Text = "Geburtstag";
//
// label6
//
this.label6.Location = new System.Drawing.Point(48, 72);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(72, 16);
this.label6.TabIndex = 17;
this.label6.Text = "Vorname";
//
// label5
//
this.label5.Location = new System.Drawing.Point(304, 376);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(120, 16);
this.label5.TabIndex = 16;
this.label5.Text = "Siege in Prozent";
//
// tbProzent
//
this.tbProzent.Location = new System.Drawing.Point(432, 376);
this.tbProzent.Name = "tbProzent";
this.tbProzent.ReadOnly = true;
this.tbProzent.Size = new System.Drawing.Size(120, 20);
this.tbProzent.TabIndex = 13;
this.tbProzent.Text = "";
//
// dpGebdatum
//
this.dpGebdatum.CustomFormat = "dd, MMM, yyyy";
this.dpGebdatum.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dpGebdatum.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.dpGebdatum.Location = new System.Drawing.Point(128, 104);
this.dpGebdatum.Name = "dpGebdatum";
this.dpGebdatum.Size = new System.Drawing.Size(104, 20);
this.dpGebdatum.TabIndex = 12;
this.dpGebdatum.ValueChanged += new System.EventHandler(this.dpGebdatum_ValueChanged);
//
// tbVorname
//
this.tbVorname.Location = new System.Drawing.Point(128, 72);
this.tbVorname.Name = "tbVorname";
this.tbVorname.Size = new System.Drawing.Size(104, 20);
this.tbVorname.TabIndex = 2;
this.tbVorname.Text = "";
//
// tbName
//
this.tbName.Location = new System.Drawing.Point(128, 40);
this.tbName.Name = "tbName";
this.tbName.Size = new System.Drawing.Size(104, 20);
this.tbName.TabIndex = 1;
this.tbName.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(48, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 5;
this.label1.Text = "Name";
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(656, 518);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
//
// tabPage3
//
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Size = new System.Drawing.Size(656, 518);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "tabPage3";
this.tabPage3.Click += new System.EventHandler(this.tabPage3_Click);
//
// bPunkte
//
this.bPunkte.Location = new System.Drawing.Point(8, 496);
this.bPunkte.Name = "bPunkte";
this.bPunkte.Size = new System.Drawing.Size(168, 23);
this.bPunkte.TabIndex = 20;
this.bPunkte.Text = "Add";
this.bPunkte.Click += new System.EventHandler(this.button2_Click);
//
// bEntfernen
//
this.bEntfernen.Location = new System.Drawing.Point(8, 528);
this.bEntfernen.Name = "bEntfernen";
this.bEntfernen.Size = new System.Drawing.Size(168, 23);
this.bEntfernen.TabIndex = 17;
this.bEntfernen.Text = "Entfernen";
this.bEntfernen.Click += new System.EventHandler(this.bEntfernen_Click);
//
// lbPersonenListe
//
this.lbPersonenListe.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colName,
this.colVorname});
this.lbPersonenListe.Location = new System.Drawing.Point(8, 16);
this.lbPersonenListe.Name = "lbPersonenListe";
this.lbPersonenListe.Size = new System.Drawing.Size(168, 464);
this.lbPersonenListe.TabIndex = 25;
this.lbPersonenListe.View = System.Windows.Forms.View.Details;
this.lbPersonenListe.SelectedIndexChanged += new System.EventHandler(this.OnIndexChange);
//
// colName
//
this.colName.Text = "Name";
this.colName.Width = 84;
//
// colVorname
//
this.colVorname.Text = "Vorname";
this.colVorname.Width = 80;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(856, 557);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.bEntfernen);
this.Controls.Add(this.lbPersonenListe);
this.Controls.Add(this.bPunkte);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.OnClose);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void tabPage1_Click(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
DataRow dr = null;
dr = dsDaten.Tables["Liste"].NewRow();
dr["Name"] = tbName.Text;
dr["Vorname"] = tbVorname.Text;
dr["Clan"] = tbClan.Text;
dr["Geburtstag"] = dpGebdatum.Value;
dr["Nick"] = tbNick.Text;
lb["Games"] = lbGames.Text;
dsDaten.Tables["Liste"].Rows.Add(dr);
FillList();
}
public void FillList() //liste füllen
{
lbPersonenListe.Items.Clear();
foreach(DataRow dr in dsDaten.Tables["Liste"].Rows)
{
ListViewItem lvi = new ListViewItem((string)dr["Name"]);
lvi.SubItems.Add((string)dr["Vorname"]);
lvi.Tag = dr;
lbPersonenListe.Items.Add(lvi);
}
}
private void tabPage3_Click(object sender, System.EventArgs e)
{
}
private void button2_Click(object sender, System.EventArgs e)
{
DataRow dr = null;
dr = dsDaten.Tables["Liste"].NewRow();
dr["Name"] = tbName.Text;
dr["Vorname"] = tbVorname.Text;
dr["Clan"] = tbClan.Text;
dr["Gebdatum"] = dpGebdatum.Value;
dr["Nick"] = tbNick.Text;
lb["Games"] = lbGames.Text;
dsDaten.Tables["Liste"].Rows.Add(dr);
FillList();
tbName.Text = "";
tbVorname.Text = "";
tbClan.Text = "";
tbNick.Text = "";
lbGames.Text = "";
}
public double BrechneDurchschnitt(int iSiege, int iLoses)
{
if ((iLoses + iSiege) == 0)
return 0;
else
return (iSiege / ((double)iLoses + (double)iSiege));
}
private void dpGebdatum_ValueChanged(object sender, System.EventArgs e)
{
}
private void OnIndexChange(object sender, System.EventArgs e)
{
DataRow dr = null;
if (lbPersonenListe.SelectedItems.Count > 0)
{
dr = (DataRow)lbPersonenListe.SelectedItems[0].Tag;
if (dr != null)
{
tbName.Text = (string)dr["Name"];
tbVorname.Text = (string)dr["Vorname"];
tbClan.Text = (string)dr["Clan"];
dpGebdatum.Value = (DateTime)dr["Gebdatum"];
tbNick.Text = (string)dr["Nick"];
lbGames.Text = (string)lb["Games"];
}
}
}
private void OnClose(object sender, System.EventArgs e)
{
dsDaten.WriteXml(Path, XmlWriteMode.WriteSchema);
}
private void bEntfernen_Click(object sender, System.EventArgs e)
{
if (lbPersonenListe.SelectedItems.Count > 0)
{
DataRow dr = (DataRow)lbPersonenListe.SelectedItems[0].Tag;
if (dr != null)
{
dsDaten.Tables["Liste"].Rows.Remove(dr);
FillList();
tbName.Text = "";
tbVorname.Text = "";
tbClan.Text = "";
tbNick.Text = "";
lbGames.Text = "";
}
}
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
}
private void lbGames_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
Ich habe alles so eingetragen wie es sollte ...
Ahso nicht wundern ich bin ITA in der Ausbildung und lerne Java C# mache ich nebenbei 🙂
$harp
Hallo $harp,
was ist deine Frage?
herbivore
Ups lol vor lauter hektik voll verplant sorry
Er nimmt alles was mit lb zu tun hat nicht an es wird immer als falsch unterstrichen .
Am besten einfach mal in eine Entwicklungsumgebung reinschmeisse der fehler dürfte gut sichtbar sein 🙂
$harp
Und wohl ebenfalls vor lauter Hektik hast Du lb nirgendwo deklariert oder instanziert...
Früher war ich unentschlossen, heute bin ich mir da nicht mehr so sicher...
lb["Games"]
soll doch sicher
dr["Games"]
sein, oder?
Habe ich doch oder nicht erklärt mich für dumm oda sowas aber hiermit habe ich das doch getan oder
this.lbGames = new System.Windows.Forms.ListBox();
$harp
[edit]
Dann habe ich aber immernoch hier
private void button1_Click(object sender, System.EventArgs e)
{
DataRow dr = null;
dr = dsDaten.Tables["Liste"].NewRow();
dr["Name"] = tbName.Text;
dr["Vorname"] = tbVorname.Text;
dr["Clan"] = tbClan.Text;
dr["Geburtstag"] = dpGebdatum.Value;
dr["Nick"] = tbNick.Text;
lb["Games"] = lbGames.Text;
dsDaten.Tables["Liste"].Rows.Add(dr);
und hier Fehler
private void button2_Click(object sender, System.EventArgs e)
{
DataRow dr = null;
dr = dsDaten.Tables["Liste"].NewRow();
dr["Name"] = tbName.Text;
dr["Vorname"] = tbVorname.Text;
dr["Clan"] = tbClan.Text;
dr["Gebdatum"] = dpGebdatum.Value;
dr["Nick"] = tbNick.Text;
lb["Games"] = lbGames.Text;
Mit der fehlermeldung :H:\c#\WindowsApplication7\WindowsApplication7\Form1.cs(502): Der Name 'lb' besteht nicht in der Klasse oder dem Namespace 'LanStat.Form1'
[/edit]
lbGames ist aber nicht gleich lb["Games"]
Und Du sagst ja dass er lb nicht kennt
Früher war ich unentschlossen, heute bin ich mir da nicht mehr so sicher...
wie programmierhans schon sagt, deine listbox heißt lbGames und nicht lb
schau dir mal in der hilfe an wie man mit einer listbox arbeitet, denn deine zugriffe sind nicht korrekt
hinzufügen eines elementes geht z.b. mit
lbGames.Items.Add("text");
man kann im prorgamm auch garnichts bei den spielen eintragen 😕
Wie schon gesagt ich mache das ganze neben meiner Ausbildung ich bekomme dabei keinerlei Hilfe alles sefmade mit hilfe von ja diesem forum und Büchern ich sag ja da is einiges dran nicht so toll aber man muss ja klein anfangen 🙂
"Jeder war mal ein Noob"
Sicher sind solche fragen wie diese in einem gewissen Sinne kinderkram für euch für mich ist es absolutes Neuland und bis jetzt macht es Spass 🙂
$harp
Es wird auch weiter Spaß machen 🙂 C# ist ne sehr produktive Sprache wo man schnell zu Ergbenisse kommt und wen man Eigeninitiative in Form von Ideen und Befragen der Standardquellen für Informationen(Suchmaschinen, Foren Suche, MSDN) zeigt, dann wird man auch gerne geholfen 🙂
Baka wa shinanakya naoranai.
Mein XING Profil.