Autor Beitrag
blumione
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: So 14.12.08 20:54 
Hallo zusammen

Ich versuche jetzt schon die ganze Zeit ein bindingNavigator zum laufen zu bringen leider komme ich nicht voran.
Die Online-Hilfen bringen mir hier auch nichts.

Wenn ich das Steuerelement "BindingNavigator" einfüge kann ich nicht die BindingSource auswählen, es steht nur "(none)".

Ich habe aber eine private Variable BindingSource festgelegt:         private BindingSource bindingSource1 = new BindingSource();

und unter Form_Load:
ausblenden volle Höhe C#-Quelltext
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:
        private void Form1_Load(object sender, EventArgs e)
        {
            String connection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Nordwind.mdb;";
            String SQL = "SELECT PersonalNr, Nachname, Vorname, Position, Foto FROM Personal";
            OleDbConnection conn = new OleDbConnection(connection);
            OleDbDataAdapter da = new OleDbDataAdapter();
            da = new OleDbDataAdapter(SQL, connection);

            try
            {
                dt = new DataTable("Personalliste");
                conn.Open();
                da.Fill(dt);
                conn.Close();

                bindingSource1.DataSource = dt;

                bindingNavigator1.BindingSource = bindingSource1;

                textBox1.DataBindings.Add("Text", bindingSource1, "PersonalNr");
                textBox2.DataBindings.Add("Text", bindingSource1, "Nachname");
                textBox3.DataBindings.Add("Text", bindingSource1, "Vorname");
                textBox4.DataBindings.Add("Text", bindingSource1, "Position");
                showFoto();
                bindingSource1.PositionChanged += new EventHandler(this.cm_PositionChanged);
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }
        }


Ich bekomme jedesmal die Fehlermeldung der Catch-Anweisung:
"Fehler E_FAIL(0x80004005) in IErrorInfo.GetDesciption."

Ich freue mich auf eure Antworten :)

Lg blumione
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: So 14.12.08 21:00 
Von welchem Typ ist denn die Exception? Sollte z.B. angezeigt werden, wenn du try erstmal weglässt.

_________________
>λ=
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Mo 15.12.08 11:24 
Bei Exceptions ist Exception.ToString() viel praktischer, weil es erheblich mehr Informationen gibt (u.a. die, nach der Sebastian fragt).

Zur Sache: Wo wird denn die DataTable erzeugt? Ich könnte mir vorstellen, dass der Designer (der ja auch einen Teil des Compilers benutzt) feststellt, dass der BindingSource noch keine Datenmenge zugeordnet ist und dass er deshalb für den BindingNavigator nicht ausgewählt werden kann.

Lösungsweg: Erzeuge im Designer eine (vermutlich beliebige) DataTable und weise diese direkt der BindingSource zu. Dann sollte auch der BindingNavigator gefüttert werden können.

Übrigens klappt das dummerweise nur, wenn sich alle Elemente in der Form-Klasse befinden. Wenn man eine separate Daten-Klasse hat, geht es nur manuell per Code. (Zumindest ist das bei #D so, über VC# kann ich nichts sagen.)

Jürgen