0

我的名字海伦。我必须在 C# 中制作简单的 Datagridview。(开始开发。)我在使用的文本框和按钮的特定列中有搜索值。(它运行良好。)

但我会在没有任何文本框的情况下直接搜索值。

我为这个结果附上了一张图片。在此处输入图像描述

    private void button2_Click(object sender, EventArgs e)
    {
        try
        {
            dataGridView1.ClearSelection();   //or restore rows backcolor to default
            for (int i = 0; i < (dataGridView1.Rows.Count); i++)
            {
                if (dataGridView1.Rows[i].Cells[1].Value.ToString().StartsWith(textBox2.Text, true, CultureInfo.InvariantCulture))
                {
                    dataGridView1.FirstDisplayedScrollingRowIndex = i;
                    dataGridView1.Rows[i].Selected = true; //It is also possible to color the row backgroud


                    return;
                }
            }
        }
        catch (Exception)
        {
        }
    }

但我不会使用文本框。只需单击列并键入,然后光标选择我键入的这个值。

请帮我。

4

0 回答 0