Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

c# datagridview combobox turning empty when getting new data

$
0
0

Hi, it is part of my code, I have 2 dataridviews in one windows form. I have added combobox column in datagridview2. 
When I select any row in datagridview1, it shows in datagridview2, it is my code

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32

    (dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["id"].Value);//3

            MySqlConnection start = new MySqlConnection(baglanti);
            MySqlCommand command = start.CreateCommand();
            command.CommandText = "SELECT id, muayine_adi, sabit_qiymet FROM tibbi_xidmetler  WHERE id = '" + id.ToString() + "'";
            start.Open();
            MySqlDataAdapter oxu = new MySqlDataAdapter(command);
            DataTable dt = new DataTable();

            oxu.Fill(dt);

            dataGridView2.DataSource = dt;

            oxuma_hekimler();
        }

void oxuma_hekimler()
        {
            MySqlConnection baglan = new MySqlConnection(baglanti);
            MySqlCommand command = baglan.CreateCommand();
            command.CommandText = "SELECT hekim_terifi.id, CONCAT (yeni_personal.adi,' ',yeni_personal.soyadi,' (',sobeler.sobe_adi,')') as 'melumat' FROM hekim_terifi INNER JOIN yeni_personal ON yeni_personal.id=hekim_terifi.personal_id INNER JOIN hekim_sobe_tanim ON hekim_sobe_tanim.hekim_id=hekim_terifi.id INNER JOIN sobeler ON sobeler.id=hekim_sobe_tanim.sobe_id";
            baglan.Open();
            MySqlDataAdapter oxu = new MySqlDataAdapter(command);
            DataTable db = new DataTable();
            oxu.Fill(db);
            Column1.DataSource = db;
            Column1.DisplayMember = "melumat";
            Column1.ValueMember = "id";
            baglan.Close();
        }

My problem is when I click datagridview1's cell, the data shows in datagridview2 and  I can choose name in combobox column. But when I click another cell in datagridview1, combobox column turning empty. I want to not changing combobox when I get data from datagridview1 to datagridview2.


Viewing all articles
Browse latest Browse all 2535

Trending Articles