This is a migrated thread and some comments may be shown as answers.

How to hide Column In Telerik RadGrid which all cells are null

1 Answer 682 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sanjeewa
Top achievements
Rank 1
Sanjeewa asked on 02 Dec 2016, 04:41 AM

I was new to telerik.
I want to hide columns in radgridview which column all cells are null values by programmatically.

thanks

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 02 Dec 2016, 11:01 AM
Hello Sanjeewa,

Thank you for writing.

To achieve this you need to iterate all rows and columns see if all values are null:
private void RadButton1_Click(object sender, EventArgs e)
{
    foreach (var col in radGridView1.Columns)
    {
        bool valueFound = false;
        foreach (var row in radGridView1.Rows)
        {
            if (row.Cells[col.Name].Value != null && row.Cells[col.Name].Value != DBNull.Value)
            {
                valueFound = true;
                break;
            }
        }
        col.IsVisible = valueFound;
    }
 
}

I have noticed that this question is posted twice and I have deleted the other post. 

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
Tags
GridView
Asked by
Sanjeewa
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or