I work in windows form c# vs 2015
i need to get text of selected value of combobox inside datagridview
i can added success in datagridview but cannot get text for it .
I replaced by column already exist his name Country
and become Country2
this code of combobox
Actually i need to get selected text of country to update data gridview
but i cannot do that so that can you help me in that ?
my update based on updated country where userid=userid
so that i need country text of combobox added
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.ColumnIndex >= 0)
- {
- if (dataGridView1.Columns[e.ColumnIndex].Name == "Save")
- {
- indexRow = e.RowIndex;
- DataGridViewRow row3 = dataGridView1.Rows[indexRow];
-
-
-
-
-
-
-
-
-
-
-
- }
- if (dataGridView1.Columns[e.ColumnIndex].Name == "Edit")
- {
-
- dataGridView1.Columns["Country"].Visible = false;
- DataGridViewComboBoxColumn cmbCol = new DataGridViewComboBoxColumn();
- cmbCol.HeaderText = "Country";
- cmbCol.Name = "Country2";
- dataGridView1.Columns.Add(cmbCol);
- dataGridView1.Columns["Country2"].DisplayIndex = 3;
-
- foreach (DataGridViewRow row2 in dataGridView1.Rows)
- {
- row2.Cells["Country2"].Value = row2.Cells["Country"].Value;
-
- var dataSourceEn = new List<Country>();
- dataSourceEn.Add(new Country() { Name = "SelectCountry", Value = 0 });
- dataSourceEn.Add(new Country() { Name = "Jordon", Value = 1 });
- dataSourceEn.Add(new Country() { Name = "Emarate ", Value = 2 });
- dataSourceEn.Add(new Country() { Name = "Saudia", Value = 3 });
- dataSourceEn.Add(new Country() { Name = "Bahreen", Value = 4 });
- dataSourceEn.Add(new Country() { Name = "Tunisi", Value = 5 });
- dataSourceEn.Add(new Country() { Name = "Algeri", Value = 6 });
- dataSourceEn.Add(new Country() { Name = "Saudan", Value = 7 });
- dataSourceEn.Add(new Country() { Name = "Syria", Value = 8 });
- dataSourceEn.Add(new Country() { Name = "Eraq", Value = 9 });
- dataSourceEn.Add(new Country() { Name = "Palestin", Value = 10 });
- dataSourceEn.Add(new Country() { Name = "Qwit", Value = 11 });
- dataSourceEn.Add(new Country() { Name = "Libanon", Value = 12 });
- dataSourceEn.Add(new Country() { Name = "Libya", Value = 13 });
- dataSourceEn.Add(new Country() { Name = "Egypt", Value = 14 });
- dataSourceEn.Add(new Country() { Name = "Moroco", Value = 15 });
- dataSourceEn.Add(new Country() { Name = "Mouritania", Value = 16 });
- dataSourceEn.Add(new Country() { Name = "Yamen", Value = 17 });
-
- cmbCol.DataSource = dataSourceEn;
- cmbCol.DisplayMember = "Name";
- cmbCol.ValueMember = "Value";
-
- }
- Save.Visible = true;
-
-
-
-
-
- }
- }
- }