Autor Beitrag
pepe-je
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 27.08.11 12:43 
Ich habe ein Problem mit dem RowFilter. Wenn ich bestimmte Werte für Spalte und Zeile einsetze, klappt es einwandfrei. Ab er ich möchte mit variablen Spalten und Zeilen arbeiten, speziell mit Knoten eines TreeViews.
Ich habe das so geschrieben;
Code:
ausblenden C#-Quelltext
1:
2:
3:
string col = parentNode.Value;
string rw = selectedNode.Value;
dv.RowFilter = "col = rw";


Aber es kommt die Fehlermeldung "Spalte [col] nicht gefunden". Was habe ich falsch gemacht?
Kann mir jemand helfen?
Schon jetzt vielen Dank
Peter

Moderiert von user profile iconTh69: Titel geändert: RowFiler->RowFilter
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 27.08.11 13:01 
Denk nochmal drüber nach:
ausblenden C#-Quelltext
1:
2:
3:
string col = "foo";
string rw = "bar";
Console.WriteLine("col = rw"); // erwartet: "foo = bar"

Was ist der Fehler, wie kannst du ihn beheben?

_________________
>λ=
pepe-je Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 27.08.11 15:44 
Hallo, Kha,

in Deinem Beispiel muß es natürlich
ausblenden C#-Quelltext
1:
Console.WriteLine(col  + " =" +  rw);					

heißen.

Aber die Sysntax von RowFilter sieht so aus
ausblenden C#-Quelltext
1:
RowFilter rf = "Spaltenname = 'Zeilenname'";					

Für eine spezielle Spalte und Zeile also so
ausblenden C#-Quelltext
1:
RowFilter rf = " Name = 'Max'";					


Dia analoge Lösung zu oben
ausblenden C#-Quelltext
1:
2:
3:
string col = parentNode.Value;
string rw = selectedNode.Value;
dv.RowFilter = " col ' +' rw ";

klappt nicht
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 27.08.11 16:03 
user profile iconpepe-je hat folgendes geschrieben Zum zitierten Posting springen:
in Deinem Beispiel muß es natürlich
ausblenden C#-Quelltext
1:
Console.WriteLine(col  + " =" +  rw);					

heißen.
Dann sollte dir klar sein, dass dein Code ebenso wenig Sinn macht wie meiner: Wie soll der Inhalt von col in den String finden? Meinetwegen noch einmal mit Quotes:
ausblenden C#-Quelltext
1:
Console.WriteLine("col = 'rw'"); // erwartet: "foo = 'bar'"					

_________________
>λ=
pepe-je Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 27.08.11 17:33 
Für Console.WriteLine ist
ausblenden C#-Quelltext
1:
2:
3:
string col = "foo";
string rw = "bar";
Console.WriteLine(col '=' rw); // erwartet: "foo = bar"

richtig. Man erhält das erwartete Ergebnis

Die Schreibweise
ausblenden C#-Quelltext
1:
2:
3:
string col = "foo";
string rw = "bar";
Console.WriteLine("col = rw");


ergibt nicht das erwartete Ergebnis

Im Falle von RowFilter gehen beide Varianten nicht, weil offenbar eine andere Syntax als bei Console.WriteLine gefordert wird.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 27.08.11 17:46 
Hallo pepe-je,

du meinst wohl
ausblenden C#-Quelltext
1:
2:
3:
col + '=' + rw
// bzw.
col + "=" + rw

(ansonsten kompiliert es ja nicht ohne Fehler).
Und außerdem hattest du das doch schon vorher als Antwort auf Kha gepostet.

Bei Strings im RowFilter müssen aber die einfachen Anführungsstriche (im String selber) stehen, d.h.
ausblenden C#-Quelltext
1:
col + "='" + rw + "'"					

Darauf hättest du aber auch nach Kha's zweitem Posting kommen können.
So, nun sollte aber dieser Thread damit beendet sein...
pepe-je Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 27.08.11 18:16 
Euch beiden vielen Dank für Eure Mühe.
Peter