Skip to content
Loading
  • Rajanikant Hawaldar
    +2
    Hi Subin
     
    Check this example and try yourself.
     
    If you want to hide all empty columns you could iterate through the DataSource collection to determine whether the corresponding property has been set for any dlgItem object:
    1. public void HideEmptyColumns()  
    2. {  
    3. objGridView.DataSource = new BindingList();//binding to gridview  
    4. var t = new Task(() =>  
    5. {  
    6. ...  
    7. });  
    8. t.Start();  
    9. t.ContinueWith(task =>  
    10. {  
    11. bool displayNameColumn = false;  
    12. bool displayFornameColumn = false;  
    13. bool displayCompanyColumn = false;  
    14. foreach (dlgItem item in (BindingList)objGridView.DataSource)  
    15. {  
    16. if (!string.IsNullOrEmpty(item.Name))  
    17. displayNameColumn = true;  
    18. if (!string.IsNullOrEmpty(item.Forname))  
    19. displayFornameColumn = true;  
    20. if (!string.IsNullOrEmpty(item.Compagny))  
    21. displayCompanyColumn = true;  
    22. }  
    23. objGridView.Columns[0].Visible = displayNameColumn;  
    24. objGridView.Columns[1].Visible = displayFornameColumn;  
    25. objGridView.Columns[2].Visible = displayCompanyColumn;  
    26. }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());  
    27. }  
    +2
  • Mohsin Arif
    +2
    1. protected void ActiveGridView5_RowDataBound(object sender, GridViewRowEventArgs e)  
    2.        {  
    3.            if (e.Row.RowType == DataControlRowType.DataRow)  
    4.            {  
    5.                for (int i = 0; i < ActiveGridView5.Rows.Count; i++)  
    6.                {  
    7.                string val = e.Row.Cells[i].ToString();  //check first cell value      
    8.                if (string.IsNullorEmpty(val))  
    9.                {  
    10.                    ActiveGridView5.Columns[i].Visible = false;     //Hides First Column      
    11.                }  
    12.                }  
    13.   
    14.            }  
    15.        }  
    try this please ??
    +2
  • Subin Thomas
    +1
    im getting exception on gvSearchEngine its saying the name does not exist in current context
    +1
  • Subin Thomas
    +1
    its not working mohsin i tried the code you suggested
    +1
  • Subin Thomas
    +1
    hey amit can you put the code in syntax highliter code so that i can understand lil easy
    +1
  • Subin Thomas
    +1
    my gridview name is ActiveGridView5 mohsin
    +1
  • Subin Thomas
    +1
    ohh is it amit okay i will paste it in vs
    +1
  • Subin Thomas
    +1
    i tried the code mohsin but its not working the null columns are also visible in the gridview
    +1
  • Subin Thomas
    +1
    still its not working mohsin null columns are also displayed
    +1