本文介绍了如何在datagridview中获取combox框的选定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在Windows窗体中工作c#vs 2015 i需要在datagridview中获取组合框选定值的文本 i可以在datagridview中添加成功,但无法获取文本。 我替换为列已经存在他的名字国家 并成为Country2 这个组合代码 实际上我需要获取国家/地区的选定文本以更新数据gridview 但是我不能这样做以便你可以帮助我吗? 我的更新基于更新的国家/地区,其中userid = userid 因此我需要添加组合框的国家/地区文本 < pre> 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]; // 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 == 编辑) { dataGridView1.Columns [ 国家/地区]。可见= 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]。值= row2.Cells [ 国家]。值; var dataSourceEn = new List< Country>(); dataSourceEn.Add( new Country(){Name = SelectCountry,值= 0 }); dataSourceEn.Add( new Country(){Name = Jordon,值= 1 }); dataSourceEn.Add( new Country(){Name = Emarate,Value = 2 }); dataSourceEn.Add( new Country(){Name = Saudia,值= 3 }); dataSourceEn.Add( new Country(){Name = Bahreen,值= 4 }); dataSourceEn.Add( new Country(){Name = Tunisi,值= 5 }); dataSourceEn.Add( new Country(){Name = Algeri,值= 6 }); dataSourceEn.Add( new Country(){Name = Saudan,Value = 7 }); dataSourceEn.Add( new Country(){Name = 叙利亚,值= 8 }); dataSourceEn.Add( new Country(){Name = Eraq,值= 9 }); dataSourceEn.Add( new Country(){Name = Palestin,Value = 10 }); dataSourceEn.Add( new Country(){Name = Qwit,值= 11 }); dataSourceEn.Add( new Country(){Name = Libanon,Value = 12 }); dataSourceEn.Add( new Country(){Name = 利比亚,值= 13 }); dataSourceEn.Add( new Country(){Name = 埃及,值= 14 }); dataSourceEn.Add( new Country(){Name = Moroco,值= 15 }); dataSourceEn.Add( new Country(){Name = Mouritania,值= 16 }); dataSourceEn.Add( new Country(){Name = Yamen,Value = 17 }); cmbCol.DataSource = dataSourceEn; cmbCol.DisplayMember = 名称; cmbCol.ValueMember = Value; } Save.Visible = true ; } } } 我尝试了什么: 如何获取combox框的选定文本在datagridview 解决方案 亲爱的艾哈迈德, 在询问 52个问题后,你我应该学到一些基本的东西。 构建一个应用程序就像玩乐高积木一样,你的任务是将标准件放在一起以获得你想要的东西。 引用:如何在datagridview中获取combox框的选定文本 这是完全无关的2个问题。 /> 引用:我需要获取组合框选定值的文本 这是10个句子中有趣的部分。你应该可以做得更好。 你应该学习如何谷歌! 只是问阅读文本组合框只给出了一百万个++答案。 提问也是一种技巧,使用谷歌或其他搜索引擎。 /> 提出问题是一项技能 [ ^ ] 在论坛中发布问题的一些指导原则 [ ^ ] I work in windows form c# vs 2015i need to get text of selected value of combobox inside datagridviewi can added success in datagridview but cannot get text for it .I replaced by column already exist his name Countryand become Country2this code of comboboxActually i need to get selected text of country to update data gridviewbut i cannot do that so that can you help me in that ?my update based on updated country where userid=useridso that i need country text of combobox added<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 解决方案 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 datagridviewThis is 2 questions completely unrelated.Quote:i need to get text of selected value of comboboxThis 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[^] 这篇关于如何在datagridview中获取combox框的选定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 17:51
查看更多