简体   繁体   English

如何从C#中的数据gridview获取选定的行值到组合框

[英]How to get selected row values to combo box from data gridview in c#

There is problem with combo box values when I double-click on row of data grid view the values from the row passes to text boxes correctly but with combobox there is problem the value is not same in combobox as in data gridview row let me show you in picture. 当我双击数据网格的行时,组合框值存在问题,该行中的值正确传递到文本框,但是使用组合框时,组合框中的值与数据网格视图行中的值不相同,让我向您展示在图片中。

示例图片

Used code 使用的代码

For Textbox: 对于文本框:

ar.txtcity.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();

For Combobox: 对于组合框:

combobox ar.txtcombo.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();

Try this one. 试试这个。

ar.txtcombo.SelectedIndex = ar.txtcombo.FindString(
                     this.dataGridView1.CurrentRow.Cells[6].Value.ToString());

I think it will help :) 我认为这会有所帮助:)

int class= int.Parse(row.Cells[6].Value.ToString());
NameOfYourComboBox.SelectedValue = class;

if the value is not in the database, you can use this; 如果该值不在数据库中,则可以使用此值;

NameOfYourComboBox.Text = row.Cells[6].Value.ToString();

I have tried this many times and it has worked fine for me with WinForms 我已经尝试了很多次,并且对WinForms来说效果很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM