簡體   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