En iyi yanıtlayıcılar
list box adet yazdırma

Soru
-
merhaba list box ile bir uygulama yapıyorum da bir sorum olacaktı.
Bir manav programı düşünün.
5-10 tane buton var her butonda başka bir meyve var.
hangi butona basılırsa o butondaki meyve ListBox a geliyor.
Sorum şu.
Ben ard arda 3 defa elma butonuna bastım. list box da alt alta 3 tane yazdırmak yerine elma (3) yazdırabilir miyim ?
Yanıtlar
-
private void button2_Click(object sender, EventArgs e) { MavavaEkle("Portakal"); } private void button1_Click(object sender, EventArgs e) { MavavaEkle("elma"); } private void MavavaEkle(string s) { bool fgfdfg = false; if (listBox1.Items.Count.Equals(0)) listBox1.Items.Add(s); else { string sayi = default(string); for (int i = listBox1.Items.Count - 1; i >= 0; i--) { var g = listBox1.Items[i].ToString(); sayi = Regex.Replace(g, s, ""); if (listBox1.Items[i].ToString().Equals(sayi + s)) { if (!Regex.IsMatch(g, @"^\d+")) listBox1.Items[i] = 1 + s; else { int yenisayi = Convert.ToInt32(sayi); listBox1.Items[i] = (++yenisayi) + s; } fgfdfg = true; break; } } if (!fgfdfg) listBox1.Items.Add(s); } }
- Yanıt Olarak İşaretleyen Özgür Tekbaş 10 Şubat 2014 Pazartesi 13:33
Tüm Yanıtlar
-
private void button2_Click(object sender, EventArgs e) { MavavaEkle("Portakal"); } private void button1_Click(object sender, EventArgs e) { MavavaEkle("elma"); } private void MavavaEkle(string s) { bool fgfdfg = false; if (listBox1.Items.Count.Equals(0)) listBox1.Items.Add(s); else { string sayi = default(string); for (int i = listBox1.Items.Count - 1; i >= 0; i--) { var g = listBox1.Items[i].ToString(); sayi = Regex.Replace(g, s, ""); if (listBox1.Items[i].ToString().Equals(sayi + s)) { if (!Regex.IsMatch(g, @"^\d+")) listBox1.Items[i] = 1 + s; else { int yenisayi = Convert.ToInt32(sayi); listBox1.Items[i] = (++yenisayi) + s; } fgfdfg = true; break; } } if (!fgfdfg) listBox1.Items.Add(s); } }
- Yanıt Olarak İşaretleyen Özgür Tekbaş 10 Şubat 2014 Pazartesi 13:33
-