簡體   English   中英

使用我的 int indexCounter 在 dataGridView 中選擇整行

[英]Selecting whole row in dataGridView with my int indexCounter

在 Form1 上,我有 int indexCounter,它自動從文本框中獲取主鍵。

我怎么能說我的 Form2 上的 dataGridView1,它應該選擇我的 int indexCounter 所在的整行?

Form1 frm = new Form1();
dataGridView1.Rows[frm.indexCounter].Selected = true;

^ 這沒有用。 我正在使用綁定。

這很奇怪。 我創建了一個Form1並設置了public int indexCounter = 3 ,然后我使用你的 2 行codes而不做任何修改來更新Form2選定行並且它可以工作。

我認為您的indexConter值以某種方式為 0,這將使所選 Row 為Rows[0] 您可能想要調試第二個代碼以在運行時查看indexCounter的值

您沒有發布關於如何獲取indexCounter值的indexCounter ,因此我無法進行更多測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM