开发者

Datagrid columns contains value

开发者 https://www.devze.com 2023-01-29 05:47 出处:网络
I\'m working application in C开发者_如何学JAVA#, .NET. How can I check in DataGridView component if some columns contains specific value?

I'm working application in C开发者_如何学JAVA#, .NET.

How can I check in DataGridView component if some columns contains specific value? I have some contains methods, but I don't know how I would use them..


If I am correct then you want Column value not RowCell Value, and its in Windows app.

You can loop through each column in datagridview

Like..

        foreach (var GridColumn in DataGridView1.Columns )
        {
             //get value from column
         }

For Rows,

       foreach (DataGridViewRow item in dataGridView1.Rows )
        {
            if(item.Cells["Column Name"].Value==your condition)
                //her you got the cell to work with

        }

You can use LINQ for same


Or you can act directly on the datasource, if it is datatable, dataset, list ..

You have methods to do that on all data collections types..


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow) 
    {
        GridViewRow row = (GridViewRow)e.Row.DataItem;
        if (row["yourColumnName"] == "YourDesiredValue")
            row["yourColumnName"] = "changevalue";
    }
}

You can find and change value of column(s)


foreach(Datagridviewrow item in datagridview1.rows)
{
    if(item.cell[indexNumber].value.tostring().contains("your word"));
    {
        messagebox.show("contains")
    }
    else
    {
        messagebox.show("NOT contains")
    }
}
0

精彩评论

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