ERLEDIGT
NEIN
NEIN
ANTWORTEN
15
15
ZUGRIFFE
1686
1686
EMPFEHLEN
-
Hallo,
ich möchte gerne meine Spalten in der ListView per Klick auf den columnHeade-Text sortieren. (wie unter windows bei der Detail-Ansicht)
lg Sonny411
-
Das sind fast schon Grundlagen.
Schau dir mal diese Videotutorials an - hier findest du viel zu List und Gridviews..
www.siore.com
Und sortieroptionen kannst du in den Eigenschaften eines Objekts einstellen...
-
sorry ich liebe die Konsole
-
so hab mir jetzt das video angeguckt.
hier wird ja alles mit einen SQL-Server verarbeitet. und c# ist es auch nicht!
also ich will einfach im VisualStudio eine ListView - sortiern per klick auf den Header-Text
-
Schau mal hier:
http://support.microsoft.com/kb/319401
-
danke norbert, aber diese seite kenn ich schon. sie ist mir einbisschen zu kompliziert und weis nicht auf anhieb wie ich das bei mir einbauen kann.
@norbert: du kennst ja schon meinen Code. Kannst du mir vielleicht verraten wo ich die Textbausteine von (http://support.microsoft.com/kb/319401) in mein Projekt einfügen muss?
lg
-
Grundsätzlich steht ganz genau darin beschrieben, wann wie wo was gemacht werden muss. Ich würde sagen, du probierst es zuerst einmal und bei auftretenden Fragen bringst du diese nochmals vor. Dabei lernst du dabei auch etwas
-
ja aber das mach ich morgen sitz seit 8:30 vorm pc und arbeit daran =)
naja - hoffenltich ist morgen ein guter tag =)
lg SONNY411
-
so ich habs jetzt probiert. Anwendung lässt sich ausführen, doch ohne Wirkung des Codes =(
Wo könnte der Fehler liegen?Geändert von sonny411 (10.08.07 um 13:22 Uhr)
-
1. Bitte halte dich an die Groß- und Kleinschreibung!!
2. Ohne zu wissen wie dein Code jetzt genau aussieht, kann dir niemand wirklich helfen.
-
Hier der Code:
Code :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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using MySql.Data.MySqlClient; //MySQL datenbank namespace rechnungspruefung_v1_060807 { public partial class Form1 : Form { public Form1(object sender, System.Windows.Forms.ColumnClickEventArgs e) { #region MySQL-Connection -----------ÖFFNEN----------------- InitializeComponent(); string connectionString = "Server=172.16.0.13;" + "Database=tmobile_spielwiese;" + "Port=3306;" + "User ID=michael;" + "Password=xxxxxxxxxxx;" + "Pooling=false"; IDbConnection dbconn; dbconn = new MySqlConnection(connectionString); dbconn.Open(); IDbCommand dbcmd = dbconn.CreateCommand(); string query = "select tmobile_rechnung20070706.rufnummer, tmobile_rechnung20070706.grundentgelt + tmobile_rechnung20070706.verbindungsentgelte + tmobile_rechnung20070706.sonstige_entgelte + tmobile_rechnung20070706.gutschriften as entgelte_tma, tmobile_egn20070706.tarif AS tma_tarif, services_06_07.tarif as dialog_tarif FROM tmobile_rechnung20070706 LEFT JOIN tmobile_egn20070706 ON (tmobile_rechnung20070706.rufnummer = tmobile_egn20070706.rufnummer) LEFT JOIN services_06_07 ON (tmobile_rechnung20070706.rufnummer=services_06_07.anummer)"; dbcmd.CommandText = query; IDataReader reader = dbcmd.ExecuteReader(); #endregion #region Ausgabe --------------------------------------- while (reader.Read()) { string rufnummer = (string)reader["rufnummer"]; string tma_tarif = (string)reader["tma_tarif"]; string entgelte_tma = Convert.ToString((double)reader["entgelte_tma"]); string dialog_tarif = "not found"; if (reader.IsDBNull(3) != true) { dialog_tarif = (string)reader["dialog_tarif"]; } string entgelte_dialog = ""; #region TARIF - OK string tarif_ok = "!NOT OK!"; if (tma_tarif == "Wholesale Mobile Internet S" & dialog_tarif == "Mobile Internet Small") { tarif_ok = "OK"; } else { if (tma_tarif == "Wholesale Mobile Internet" & dialog_tarif == "Mobile Internet Mobil") { tarif_ok = "OK"; } else { if (tma_tarif == "Wholesale Mobile Internet XL" & dialog_tarif == "Mobile Internet XL") { tarif_ok = "OK"; } else { if (tma_tarif == "Wholesale Mobile Internet XL" & dialog_tarif == "Mobile Internet XL") { tarif_ok = "OK"; } else { if (tma_tarif == "Mobile Internet Medium" & dialog_tarif == "Mobile Internet Mobil") { tarif_ok = "OK"; } else { if (tma_tarif == "Gutschrift Wholesale Mobile Internet" & dialog_tarif == "Mobile Internet Mobil") { tarif_ok = "Gutschrift"; } else { if (tma_tarif == "Rabatt auf Grundgebühr" & dialog_tarif == "Mobile Internet Mobil") { tarif_ok = "Rabatt auf Grundgebühr"; } else { if (tma_tarif == "Rabatt auf Grundgebühr" & dialog_tarif == "Mobile Internet Small") { tarif_ok = "Rabatt auf Grundgebühr"; } else { if (tma_tarif == "Rabatt auf Grundgebühr" & dialog_tarif == "Mobile Internet XL") { tarif_ok = "Rabatt auf Grundgebühr"; } else { if (tma_tarif == "Mobile Internet Small" & dialog_tarif == "Mobile Internet Small") { tarif_ok = "OK"; } else { if (tma_tarif == "Gutschrift Wholesale Mobile Internet XL" & dialog_tarif == "Mobile Internet Mobil") { tarif_ok = "Gutschrift"; } else { if (tma_tarif == "Gutschrift Wholesale Mobile Internet XL" & dialog_tarif == "Mobile Internet Small") { tarif_ok = "Gutschrift"; } else { if (tma_tarif == "Gutschrift Wholesale Mobile Internet XL" & dialog_tarif == "Mobile Internet XL") { tarif_ok = "Gutschrift"; } else { if (tma_tarif == "Wholesale Mobile Internet" & dialog_tarif == "Mobile Internet Small") { tarif_ok = "OK"; } else { if (tma_tarif == "Gutschrift Wholesale Mobile Internet S" & dialog_tarif == "Mobile Internet Small") { tarif_ok = "Gutschrift"; } else { if (tma_tarif == "Gutschrift Wholesale Mobile Internet" & dialog_tarif == "Mobile Internet Small") { tarif_ok = "Gutschrift"; } else { if (tma_tarif == "Gutschrift Wholesale Mobile Internet S" & dialog_tarif == "Mobile Internet Mobil") { tarif_ok = "Gutschrift"; } else { } } } } } } } } } } } } } } } } } // TARIF - OK --------------------------------------------------------------------------------------- #endregion ListViewItem x = new ListViewItem(new string[] { rufnummer, tma_tarif, "€ "+entgelte_tma, dialog_tarif, entgelte_dialog, tarif_ok }); if (tarif_ok == "!NOT OK!") { x.BackColor = Color.Red; x.ForeColor = Color.White; lv_ausgabe.Items.Add(x); lv_ausgabe.Sort(); } ListViewItemComparer sorter = new ListViewItemComparer(e.Column); lv_ausgabe.ListViewItemSorter = sorter; lv_ausgabe.Sort(); } #endregion #region MySQL-Connection -----------SCHLIESSEN----------------- reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; dbconn.Close(); dbconn = null; #endregion } private void Lv_ausgabe_ColumnClick(object sender, System.Windows.Forms.ColumnClickEventArgs e, System.Windows.Forms.ListView lv_ausgabe) { ListViewItemComparer sorter = new ListViewItemComparer(e.Column); lv_ausgabe.ListViewItemSorter = sorter; lv_ausgabe.Sort(); } private void Form1_Load(object sender, EventArgs e) { } } } public class ListViewItemComparer : IComparer { private int column; private bool numeric = false; public int Column { get { return column; } set { column = value; } } public bool Numeric { get { return numeric; } set { numeric = value; } } public ListViewItemComparer(int columnIndex) { Column = columnIndex; } public int Compare(object x, object y) { ListViewItem listX = (ListViewItem)x; ListViewItem listY = (ListViewItem)y; if (Numeric) { // Convert column text to numbers before comparing. // If the conversion fails, just use the value 0. decimal listXVal, listYVal; try { listXVal = Decimal.Parse(listX.SubItems[Column].Text); } catch { listXVal = 0; } try { listYVal = Decimal.Parse(listY.SubItems[Column].Text); } catch { listYVal = 0; } return Decimal.Compare(listXVal, listYVal); } else { // Keep the column text in its native string format // and perform an alphabetic comparison. string listXText = listX.SubItems[Column].Text; string listYText = listY.SubItems[Column].Text; return String.Compare(listXText, listYText); } } }
Meine Fehlermeldung: Keine Überladung für die Form1-Methode nimmt 0 Argumente an. in Program.cs
-
Wozu hast du dies im Konstruktor der Form1?
Code :1
object sender, System.Windows.Forms.ColumnClickEventArgs e
?
-
-
Also, den Konstruktor solltest du nicht als EventHandler missbrauchen. Dafür hast du ja private void Lv_ausgabe_ColumnClick. Hier solltest du deine Funktionalität hineinpacken.
-
habs jetzt hineingeopackt funkt aber trotzdem nicht:
Code :1
Keine Überladung für die Form1-Methode nimmt 0 Argumente an.
Ich bin am verzweifeln =(
Ähnliche Themen
-
ListView mit mehreren Spalten
Von andralin im Forum .NET WPF & SilverlightAntworten: 0Letzter Beitrag: 27.03.09, 15:26 -
ListView feste Spalten
Von MasterEvil im Forum Visual Basic 6.0Antworten: 3Letzter Beitrag: 16.09.05, 09:28 -
ListView Spalten auslesen
Von nils31 im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 03.07.05, 18:20 -
ListView - Spalten sortieren
Von meto im Forum .NET ArchivAntworten: 1Letzter Beitrag: 23.11.04, 09:48 -
[Listview] Wie Zeilen in Spalten ansprechen
Von NRFi im Forum .NET ArchivAntworten: 1Letzter Beitrag: 03.06.04, 16:07





Zitieren

Login





