0

Using : VS2010, .Net 3.5. I apologize for my poor Title.

I have a string item which, i am sure, is available in a datagridview. Now i want to select the row, where the item belongs.

            tableName = tmp._Table;     //I have my table_name here

//This following code shows what my dgvtablelist have.

            dgvTablesList.DataSource = CS.getAllTables(serverName, dbName, authenticationType, logIn, passWord);

SO, how would I select my tableName in the DataGridVIew?

I dont have any **index

4

2 回答 2

1

首先找到搜索值的gridview行索引:

String searchValue = "your_table_name";
int rowIndex = -1;
foreach(DataGridViewRow row in DataGridView1.Rows)
{
    if(row.Cells[1].Value.ToString().Equals(searchValue))
    {
        rowIndex = row.Index;
        break;
    }
}

然后选择那个..

dataGridView1.Rows[rowIndex].Selected = true;
于 2013-01-07T14:30:57.597 回答
0

您应该尝试这样做以选择 DataGridView 行。

DataGridView1.CurrentCell = DataGridView.Rows[rowIndex].Cells[0];

希望这可以帮助。

于 2013-01-07T15:16:14.280 回答