Testumgebung:
Win XP
Visual C# 2008 Express Edition
Wann funktioniert das Programm:
- Wenn man mit <DbArtist> arbeitet oder
- wenn man mit <object> arbeitet und this.dbArtistList.FetchIn(); im Form1-Konstruktor aufruft.
Wann funktioniert das Programm nicht:
Wenn man mit <object> arbeitet und this.dbArtistList.FetchIn(); nicht im Form1-Konstruktor aufruft. Im DataGridView wird zwar eine Zeile eingetragen, allerdings sind die Zelleninhalte leer.
Oberfläche:
- DataGridView dataGridView1
- Button btnAddArtist
Programm:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { DbArtistList dbArtistList = new DbArtistList(); public Form1() { InitializeComponent(); this.dataGridView1.DataSource = dbArtistList.cDbArtist;
this.dbArtistList.FetchIn(); } private void Form1_Load(object sender, EventArgs e) { } private void btnAddArtist_Click(object sender, EventArgs e) { this.dbArtistList.FetchIn(); } private void OnArtistsSelected(object dgv) { this.dbArtistList.FetchIn(); } }
public class DbArtist { public int iId { get; set; } public string sName { get; set; } } public class DbArtistList { public BindingList<object> cDbArtist = new BindingList<object>();
public void FetchIn() { DbArtist dbArtist = new DbArtist(); dbArtist.iId = 1; dbArtist.sName = "a";
this.cDbArtist.Add(dbArtist); } } } |
Könnt ihr mir das bestätigen? Ist das ein Bug? Ev. ein bekannter Bug?