搜索后选择gridview行

时间:2016-07-18 08:26:34

标签: c# gridview

表格1和2

我从其他表单点击搜索后如何自动选择? 我使用C#。下面的文本框仅用于存储(检查)我希望选择带有gridview的表单1 我在下面的表格2中的代码:

enter image description here

private void simpleButton1_Click(object sender, EventArgs e)
    {
        cari();
    }

public void cari()
    {
        SqlDataAdapter adapter = new SqlDataAdapter(command.CommandText, myConnection);
        try
        {
            ds.Tables.Clear();

            command.Connection = myConnection;
            command.CommandText = "select * from General.genre WHERE genre Like  '%"+textEdit1.Text.ToString()+"%' or code like '%"+textEdit1.Text+"%'";
            myConnection.Open();

          var  buka = command.ExecuteReader();

            if (buka.Read())
            {
                 textEdit2.Text = buka[1].ToString();

            }
            else 
                    {
                MessageBox.Show("type genre");
            }


          //  MessageBox.Show("kebaca");

        }
        catch (System.Exception ex)
        {


            MessageBox.Show("error" + ex);
        }

        myConnection.Close();
    }

1 个答案:

答案 0 :(得分:0)

dataGrid.SelectedRows.Clear();
foreach(DataGridViewRow row in dataGrid.Rows)
{
    if(YOUR CONDITION)
       row.Selected = true;
}