繁体   English   中英

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

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

当我双击数据网格的行时,组合框值存在问题,该行中的值正确传递到文本框,但是使用组合框时,组合框中的值与数据网格视图行中的值不相同,让我向您展示在图片中。

示例图片

使用的代码

对于文本框:

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

对于组合框:

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

试试这个。

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

我认为这会有所帮助:)

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

如果该值不在数据库中,则可以使用此值;

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

我已经尝试了很多次,并且对WinForms来说效果很好

暂无
暂无

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

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