Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
<pre>private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)  
       {  
           if (e.ColumnIndex >= 0)  
           {  
               if (dataGridView1.Columns[e.ColumnIndex].Name == "Save")  
               {  
                   indexRow = e.RowIndex; // get the selected Row Index  
                   DataGridViewRow row3 = dataGridView1.Rows[indexRow];  
                   //ComboBox cmbBox = e.Control as ComboBox;  
                   //cmbBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);  
                   //MessageBox.Show(str);  
                   //dataGridView1.CurrentRow.Cells["Country"].Value.ToString();  
                   // dataGridView1.CurrentRow.Cells[0].Value.ToString();  
                   //QrClasses qrc = new MatrixBarcode.QrClasses();  
                   //string valueupdate = qrc.updatedatagridview(dataGridView1.CurrentRow.Cells[5].Value.ToString(), row3.Cells[2].Value.ToString());  
                   //if (valueupdate != null)  
                   //{  
                   //    MessageBox.Show("??? ?? ??????? ?????");  
                   //}  
               }  
               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;  
                  
  
  
  
  
               }  
           }  
       }  


What I have tried:

How to get selected text for combox box in datagridview
Posted
Updated 10-Mar-17 18:59pm

1 solution

Dear Ahmed,
After asking 52 questions, you should have learned a few basic things.
Building an app is like playing with Legos, your task is to put together standard pieces to get what you want.
Quote:
How to get selected text for combox box in datagridview

This is 2 questions completely unrelated.

Quote:
i need to get text of selected value of combobox

This is the interesting part out of 10 sentences. You should be able to do better.

You should really learn how to Google !
Just asking read text combobox gives only a million ++ answers.

Asking a question is a skill, using Google or another search engine too.
Asking questions is a skill[^]
Some guidelines for posting questions in the forums[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900