开发者

How can i ask grid view to know which cell is active and pass cell's value to my function?

开发者 https://www.devze.com 2023-02-04 03:01 出处:网络
Is cellvaluechanged event suitable for this ? how? void filterDataGridView(DataGridView dgv, string columnName, string filterValue)

Is cellvaluechanged event suitable for this ? how?

void filterDataGridView(DataGridView dgv, string columnName, string filterValue)
    {
        foreach (DataGridViewRow row 开发者_如何学编程in dgv.Rows)
        {
            if (row.Cells[columnName].Value.ToString().Contains(filterValue))
            {
                row.Visible = true;
            }
            else row.Visible = false;
        }
    }

i need too send cell value that user write it,to filtervalue of my function.how can i do that?


If you want to react on the user typing text in on of your cells I would recommend CellValidating event.

  • You write some text in on of your cells
  • Cell_validating occurs
  • you call your filter method and you may modify some other dataGrid (in your example hide/show rows on given value)

HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消