c# combox veri aktarma

ByWasco

Kilopat
Katılım
24 Ocak 2015
Mesajlar
236
Daha fazla  
Cinsiyet
Erkek
Öncelikle burdaki veriler hepsi sıradan isimler ve linkler asıl proje için denemeler yapiyorum.
Combobox1'e 3 veri giriyorum.
Veri 1 Steam, combox2'ye aktarıldığında steam indir ve steam direk indir adında 2 seçenek ekledim.
Veri 1 Origin, combox2'ye aktarıldığında origin indir seçeneği ekledim.
Veri 3 Epic, combox2'ye aktarıldığında epic indir seçeneği ekledim.
Her birine ilgili ziyaret linklerini ekledim lakin combobox2'de olayı çözemedim tanımlayamadım.Şöyle bir sorun ile karşılaştım.Şimdi combobox 2'de steam indir direk steam sayfasına yönelendiriyor lakin steam direk indir seçeneği alttaki origin indir seçeneğini ziyaret ediyor sorunu nasıl çözebilirim acaba?

İndir botunu kodları.
Kod:
            if (comboBox1.SelectedIndex + comboBox2.SelectedIndex == 0)
            {
                System.Diagnostics.Process.Start("https://steamcommunity.com/");
            }
            else if (comboBox1.SelectedIndex + comboBox2.SelectedIndex == 1)
            {
                System.Diagnostics.Process.Start("https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe");
            }

            else if (comboBox1.SelectedIndex + comboBox2.SelectedIndex == 2)
                {
                    System.Diagnostics.Process.Start("https://www.origin.com/tur/en-us/store");
                }
           

            else if (comboBox1.SelectedIndex + comboBox2.SelectedIndex == 3)
            {
                System.Diagnostics.Process.Start("https://www.epicgames.com/store/tr/");
            }
        }
 

Dosya Ekleri

  • 1s.png
    1s.png
    88,5 KB · Görüntüleme: 39
  • 2s.png
    2s.png
    64,1 KB · Görüntüleme: 32
Son düzenleyen: Moderatör:
Programlama sıkıntılı. Yöntemin sıkıntılı. Yeniden programlaman lazım.

Veya şu şekilde yapabilirsin.

C#:
   if (comboBox1.SelectedIndex == 0 && comboBox2.SelectedIndex == 0){
                System.Diagnostics.Process.Start("https://steamcommunity.com/");
            }else if (comboBox1.SelectedIndex == 1 && comboBox2.SelectedIndex == 1){
                System.Diagnostics.Process.Start("https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe");
            }else if (comboBox1.SelectedIndex == 2 && comboBox2.SelectedIndex == 2){
                    System.Diagnostics.Process.Start("https://www.origin.com/tur/en-us/store");
            }else if (comboBox1.SelectedIndex == 3 && comboBox2.SelectedIndex == 3){
                    System.Diagnostics.Process.Start("https://www.epicgames.com/store/tr/");
            }
        }
 
If else yerine switch kullanın. Birden fazla indexleme için if else kullanın.

C#:
switch(comboBox1.SelectedIndex){
    case 0:
    if(comboBox2.SelectedIndex == 0) {
        System.Diagnostics.Process.Start("https://steamcommunity.com/");
    }
    else {
         System.Diagnostics.Process.Start("https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe");
    }
    break;
}
Bunu geliştirirsiniz. Değişkenlerle çalışırsanız yine benzer şeyler yapabilirsiniz. Bir deneyin.
 
ilk kod çalıştı diğerleri çalışmadı maalesef.
If else yerine switch kullanın. Birden fazla indexleme için if else kullanın.

C#:
switch(comboBox1.SelectedIndex){
    case 0:
    if(comboBox2.SelectedIndex == 0) {
        System.Diagnostics.Process.Start("https://steamcommunity.com/");
    }
    else {
         System.Diagnostics.Process.Start("https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe");
    }
    break;
}
Bunu geliştirirsiniz. Değişkenlerle çalışırsanız yine benzer şeyler yapabilirsiniz. Bir deneyin.
Hocam bu kod çalıştı.Ben buna combobaxdaki birinci verinin combobox 2ye aktarılan veriye daha fazla veri eklemek gibi bir durumum olursa ne yapmam gerek acaba? steam indir, steam direk indire bir yada daha fazla seçenek eklemek istersek? @TheAny

çalışan kodlar.
[CODE title="Kodlar"] switch (comboBox1.SelectedIndex)
{
case 0:
if (comboBox2.SelectedIndex == 0)
{
System.Diagnostics.Process.Start("https://steamcommunity.com/");
}
else
{
System.Diagnostics.Process.Start("https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe");
}


break;
}
switch (comboBox1.SelectedIndex)
{
case 1:
if (comboBox2.SelectedIndex == 1)
{
System.Diagnostics.Process.Start("https://www.origin.com/tur/en-us/store");
}
else
{
System.Diagnostics.Process.Start("https://www.origin.com/tur/en-us/store");
}
break;
}
switch (comboBox1.SelectedIndex)
{
case 2:
if (comboBox2.SelectedIndex == 2)
{
System.Diagnostics.Process.Start("https://www.epicgames.com/store/tr/");
}
else
{
System.Diagnostics.Process.Start("https://www.epicgames.com/store/tr/");
}
break;

}[/CODE]
 
Hocam, comboBox1 selected index changed eventine aşağıdaki kodları koyun. Bu comboBox1de seçmiş olduğunuz seçeneği eklemek istediğiniz şeylerle comboBox2'ye ekleyecek. comboBox2.Items.Add(sltctd.ToString() + "Havadan çek") gibi. slctd değişkeni bir nesne ve comboBox1 de seçili olan itemin verilerini çekmemize yarıyor. Eğer 10-20 tane böyle seçenek eklemek isterseniz array oluşturursunuz, sonrasında bir for yada while loop başlatırsınız. (for daha mantıklı olur) comboBox2.Items.Add(slctd.ToString() + array); Böylece eklemek istediklerinizi ekler. Bunun içinde örnek atayım. Düğmeye de şu atacağımı geliştirip yazarsanız çalışacaktır. Düğmede çoklu durumlar için yine switch case ile daha kolay geliştirme yapılabilir. Şuan yazacak çok vaktim yok. Daha sonrasında ona da alternatif atarım.
C#:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox2.Items.Clear();
            Object slctd = comboBox1.SelectedItem;
            comboBox2.Items.Add(slctd.ToString() + " Direkt İndir");
            comboBox2.Items.Add(slctd.ToString() + " İndir");
        }

C#:
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string[] menu = { " Direkt İndir", " İndir", " Doğrudan İndir", " Havadan İndir" };
            int l = menu.Length;
            comboBox2.Items.Clear();
            Object slctd = comboBox1.SelectedItem;
            
            for (int i = 0; i < l; i++)
            {
                comboBox2.Items.Add(slctd.ToString() + menu[i]);
            }
        }

C#:
private void button1_Click(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0: if (comboBox2.SelectedIndex == 0)
                    {
                        Process.Start("https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe");
                    }
                    else
                    {
                        Process.Start("https://steamcommunity.com/");
                    }
                    break;
                case 1: if (comboBox2.SelectedIndex == 1)
                    {
                        Process.Start("https://www.epicgames.com/store/tr/");
                    }
                    else
                    {
                        MessageBox.Show("Bu link henüz yok.", "Uyarı");
                    }
                    break;
                case 2: if (comboBox2.SelectedIndex == 1)
                    {
                        Process.Start("https://www.origin.com/tur/en-us/store");
                    }
                    else
                    {
                        MessageBox.Show("Bu link henüz yok.", "Uyarı");
                    }
                    break;
            }
            
        }
 

Geri
Yukarı