Filtering values for GridViewItems I have this function in my application that I need to simplify in order to improve the code quality:

void FilterValues()
    {
        List&lt;SecondaryStockRoomDefenition&gt; GridViewItems = new List&lt;SecondaryStockRoomDefenition&gt;();
        GridViewItems = StockRooms.ToList();

        if (cboPrimaryStockRoom.SelectedValue.ToString().Trim() != "0")
        {
            GridViewItems =
           StockRooms.Where((SecondaryStockRoomDefenition, index)
               =&gt; GridViewItems[index].DeletedSecondaryStockRoom == false
                  &amp;&amp; GridViewItems[index].PrimaryStockroomCode == cboPrimaryStockRoom.SelectedValue.ToString().Trim()).ToList();
        }
        if( txtSecondaryStockRoomCode.Text != "" )
        {
            GridViewItems = GridViewItems.Where((SecondaryStockRoomDefenition,index) =&gt; 
                GridViewItems[index].DeletedSecondaryStockRoom == false
                &amp;&amp; GridViewItems[index].SecondaryStockroomCode == txtSecondaryStockRoomCode.Text.Trim()).ToList();
        }
        if (txtSecondaryStockRoomName.Text != "")
        {
            GridViewItems = GridViewItems.Where((SecondaryStockRoomDefenition, index) =&gt;
                GridViewItems[index].DeletedSecondaryStockRoom == false
                &amp;&amp; GridViewItems[index].SecondaryStockroomDescription.Contains(txtSecondaryStockRoomName.Text.Trim())).ToList();
        }
        if (txtStockRoomLocationCode.Text != "")
        {
            GridViewItems = GridViewItems.Where((SecondaryStockRoomDefenition, index) =&gt;
                GridViewItems[index].DeletedSecondaryStockRoom == false
                &amp;&amp; GridViewItems[index].SecondaryStockroomLocationCode == txtStockRoomLocationCode.Text.Trim()).ToList();
        }
        if (cboStockRoomCategory.SelectedValue.ToString().Trim() != "0")
        {
            GridViewItems = GridViewItems.Where((SecondaryStockRoomDefenition, index) =&gt;
                GridViewItems[index].DeletedSecondaryStockRoom == false
                &amp;&amp; GridViewItems[index].SecondaryStockroomCategory == cboStockRoomCategory.SelectedValue.ToString().Trim()).ToList();
        }

        if (txtStockRoomType.Text != "")
        {
            GridViewItems = GridViewItems.Where((SecondaryStockRoomDefenition, index) =&gt;
                GridViewItems[index].DeletedSecondaryStockRoom == false
                &amp;&amp; GridViewItems[index].SecondaryStockroomType == txtStockRoomType.Text.Trim()).ToList();
        }
        if (cboExpectedUserName.SelectedValue.ToString().Trim() != "0")
        {
            GridViewItems = GridViewItems.Where((SecondaryStockRoomDefenition, index) =&gt;
                GridViewItems[index].DeletedSecondaryStockRoom == false
                &amp;&amp; GridViewItems[index].ExpectedUserNameForCommissionEntry == cboExpectedUserName.SelectedValue.ToString().Trim()).ToList();
        }


        dgvCompanyProfileDetails.DataSource = null;
        dgvCompanyProfileDetails.Rows.Clear();
        dgvCompanyProfileDetails.DataSource = GridViewItems;
    }
Just a few things from me:


Check the way you name variables.  Local variables by defacto standard are lower case camel.  See here for more details Microsoft naming conventions.

GridViewItems becomes gridViewItems
I personally try to use implicit local variables where the type is obvious.  This is more a personal preference but Microsoft do recommend as well.  See C# coding conventions for more details.
If gridViewItems is going to be assigned to stockrooms immediately, why not just do straight off the cuff?

var gridViewItems = StockRooms.ToList();

I would convert this method into a bunch of smaller functions.  Perhaps something like (excuse any compile options as I could not fully test this code):

void FilterValues()
{
    dgvCompanyProfileDetails.DataSource = null;
    dgvCompanyProfileDetails.Rows.Clear();
    dgvCompanyProfileDetails.DataSource = Filter(StockRooms).ToList();
}

private IEnumerable&lt;SecondaryStockRoomDefenition&gt; Filter(IEnumerable&lt;SecondaryStockRoomDefenition&gt; stockRooms)
{
    // filter the stock rooms on each function call
    stockRooms = FilterStockRooms(stockRooms, cboPrimaryStockRoom, p =&gt; p.PrimaryStockroomCode);
    stockRooms = FilterStockRooms(stockRooms, txtSecondaryStockRoomCode.Text, p =&gt; p.SecondaryStockroomCode);
    stockRooms = FilterStockRooms(stockRooms, txtSecondaryStockRoomName.Text, (p, v) =&gt; p.SecondaryStockroomDescription.Contains(v));
    stockRooms = FilterStockRooms(stockRooms, txtStockRoomLocationCode.Text, p =&gt; p.SecondaryStockroomLocationCode);
    // .. etc

    return stockRooms;
}

private IEnumerable&lt;SecondaryStockRoomDefenition&gt; FilterStockRooms(IEnumerable&lt;SecondaryStockRoomDefenition&gt; rooms, ComboBox combo, Func&lt;SecondaryStockRoomDefenition, string&gt; filter)
{
    var value = combo.SelectedValue.ToString();

    return HasValue(value, "0") ? FilterStockRooms(rooms, v =&gt; filter(v).Equals(value, StringComparison.InvariantCultureIgnoreCase)) : rooms;   
}

private IEnumerable&lt;SecondaryStockRoomDefenition&gt; FilterStockRooms(IEnumerable&lt;SecondaryStockRoomDefenition&gt; rooms, string text, Func&lt;SecondaryStockRoomDefenition, string&gt; filter)
{
    return HasValue(text) ? FilterStockRooms(rooms, v =&gt; filter(v).Equals(text, StringComparison.InvariantCultureIgnoreCase)) : rooms;
}

private IEnumerable&lt;SecondaryStockRoomDefenition&gt; FilterStockRooms(IEnumerable&lt;SecondaryStockRoomDefenition&gt; rooms, string text, Func&lt;SecondaryStockRoomDefenition, string, bool&gt; filter)
{
    return HasValue(text) ? FilterStockRooms(rooms, v =&gt; filter(v, text)) : rooms;
}

// The question marks are because I wasn't sure of the StockRooms type
private IEnumerable&lt;SecondaryStockRoomDefenition&gt; FilterStockRooms(IEnumerable&lt;SecondaryStockRoomDefenition&gt; rooms, Func&lt;SecondaryStockRoomDefenition, bool&gt; filter)
{
    return rooms.Where(p =&gt; p.DeletedSecondaryStockRoom == false &amp;&amp; filter(p));
}

private bool HasValue(string value)
{
    return !string.IsNullOrWhiteSpace(value);
}

private bool HasValue(string value, string compareTo)
{
    return HasValue(value) &amp;&amp; value.Trim() != compareTo;
}