private void HOgrencilerGuncelleForm_Load(object sender, EventArgs e) { //hogrenciform devamı... //2.yöntem veri ataası ise bu farklı form olduğu için gelen formda datagridview1 deki ogrencilerID değerini globala alıp public yaptık ve burdada globala ogrenciID globalde public tanımaldık görüldüğü gibi Ogrenciler sonuc = db.Ogrenciler.FirstOrDefault(k => k.OgrencilerID == ogrenciID); try { comboBoxSinifi.Text = db.Sınıflar.FirstOrDefault(k => k.SiniflarID == sonuc.SinifID).SinifSubesi; } catch (Exception) { comboBoxSinifi.Text = ""; } //3-yöntem ise ogrman.kangrubuyukle(comboBoxKanGrubu); try { comboBoxKanGrubu.Text = db.KanGruplari.FirstOrDefault(k => k.KanGruplariID == sonuc.KanGrubuID).KanGrubuAdi; } catch (Exception) { comboBoxKanGrubu.Text = ""; } try { textBoxAdres.Text = db.Ogrenciler.FirstOrDefault(k => k.OgrencilerID == ogrenciID).Adres; } catch (Exception) { textBoxAdres.Text = ""; } try { textBoxKilo.Text = db.Ogrenciler.FirstOrDefault(k => k.OgrencilerID == ogrenciID).OgrenciKilo.ToString(); } catch (Exception) { textBoxKilo.Text = ""; } try { textBoxBoy.Text = db.Ogrenciler.FirstOrDefault(k => k.OgrencilerID == ogrenciID).OgrenciBoy.ToString(); } catch (Exception) { textBoxBoy.Text = ""; } }
private void dataGridView1_DoubleClick(object sender, EventArgs e) { HOgrencilerGuncelleForm Guncelformu = new HOgrencilerGuncelleForm(); ogr_id = (int)dataGridView1.CurrentRow.Cells["OgrencilerID"].Value; Ogrenciler sonuc = db.Ogrenciler.FirstOrDefault(k => k.OgrencilerID == ogr_id); //var veri türüde da olur Guncelformu.ogrenciID = ogr_id; try { Guncelformu.maskedTextBoxTC.Text = dataGridView1.CurrentRow.Cells["OgrenciTC"].Value.ToString(); } catch (Exception) { Guncelformu.maskedTextBoxTC.Text = ""; } try { Guncelformu.textBoxAdi.Text = dataGridView1.CurrentRow.Cells["OgrenciAdi"].Value.ToString(); } catch (Exception) { Guncelformu.textBoxAdi.Text = ""; } try { Guncelformu.textBoxSoyadi.Text = dataGridView1.CurrentRow.Cells["OgrenciSoyadi"].Value.ToString(); } catch (Exception) { Guncelformu.textBoxSoyadi.Text = ""; } try { string Csecim = dataGridView1.CurrentRow.Cells["Cinsiyeti"].Value.ToString(); if (Csecim == "Kadın" || Csecim == "kadın") { Guncelformu.radioButtonKadin.Checked = true; } else if (Csecim == "Erkek" || Csecim == "erkek") { Guncelformu.radioButtonErkek.Checked = true; } } catch (Exception) { Guncelformu.radioButtonErkek.Checked = false; Guncelformu.radioButtonKadin.Checked = false; } try { Guncelformu.dateTimePickerDogumTarihi.Text = dataGridView1.CurrentRow.Cells["DogumTarihi"].Value.ToString(); } catch (Exception) { Guncelformu.dateTimePickerDogumTarihi.Text = "1.1.1990"; } //combobaxların katagorileri yüklemek için ya burda yada atıcağı pencerede yapabiliriz ama öncelikle katogorileri sonra verilerini combolabox.text lerine vermek zorundayız kategoriler bir yöntemi varda verilerini yollamanın //1.yöntem Guncelformu.comboBoxDogumYeri.DataSource = db.iller.ToList(); //classa atılabilir//atamadım:D Guncelformu.comboBoxDogumYeri.DisplayMember = "ilAdi"; Guncelformu.comboBoxDogumYeri.ValueMember = "illerID"; //string dyeri = dataGridView1.CurrentRow.Cells["DogumYeri"].Value.ToString(); //var dyerisonuc = db.iller.FirstOrDefault(k => k.ilAdi == dyeri); //Guncelformu.comboBoxDogumYeri.Text = db.iller.FirstOrDefault(k => k.ilAdi == dyerisonuc.ilAdi).ilAdi; // yada //string dyeri = dataGridView1.CurrentRow.Cells["DogumYeri"].Value.ToString(); //Guncelformu.comboBoxDogumYeri.Text = db.iller.FirstOrDefault(k => k.ilAdi == dyeri).ilAdi; //yada ogrenciID den daha iyi öncelikle an başa satırın ogrencilerIDsi bir değişkene atanır ardından alınan değerle db den ogrencilerden ogrencilerID ile karşılatırır bunuda ogrenciler yada var veri türüne eşitler son ra bu try { Guncelformu.comboBoxDogumYeri.Text = db.iller.FirstOrDefault(k => k.illerID == sonuc.DogumYeriID).ilAdi; } catch (Exception) { Guncelformu.comboBoxDogumYeri.Text = ""; } //2.Yöntem //burda kategorileri tanımlayıp diğer formda verini itama vs olabilir Guncelformu.comboBoxSinifi.DataSource = db.Sınıflar.ToList(); Guncelformu.comboBoxSinifi.DisplayMember = "SinifSubesi"; Guncelformu.comboBoxSinifi.ValueMember = "SiniflarID"; Guncelformu.ShowDialog(); }