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

Setting Column to visible having no effect

2 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ilija
Top achievements
Rank 1
Ilija asked on 29 Jul 2008, 08:59 PM
Hi Guys,

I am setting a RadGrid column's visibility to false on a toolbar button press, and then back to true again when they press it again(a toggle). The problem I am having is that when I toggle the column invisible, it doesn't become visible again on the next toggle. I am just setting the Visible property of the column and I'm not sure why this is happening.

Here's what's going on in the code on the button click event:

else if (e.Item.Value.Substring(0, 2).Equals("CC")) 
    bool hide = true
    string[] colDel = e.Item.Value.Split(delimiterChars); 
    string colName = colDel[1]; 
    RadToolBarButton mybut = (RadToolBarButton)e.Item; 
    if (mybut.Checked) 
    { 
        mybut.Checked = false
        mybut.ImageUrl = ""
        hide = true
    } 
    else 
    { 
        mybut.Checked = true
        mybut.ImageUrl = "/Images/Toolbar/update.gif"
        hide = false
    } 
    foreach (GridColumn rc in rgAcct.MasterTableView.Columns) 
    { 
        if (rc.HeaderText.Equals(colName)) 
        { 
            if (hide) 
            { rc.Visible = false; } 
            else 
            { rc.Visible = true; } 
 
            break
        } 
    } 
 
    foreach (GridColumn rc in rgAcct.MasterTableView.AutoGeneratedColumns) 
    { 
        if (rc.HeaderText.Equals(colName)) 
        { 
            if (hide) 
            { rc.Visible = false; } 
            else 
            { rc.Visible = true; } 
 
            break
        } 
    } 

2 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 29 Jul 2008, 10:13 PM
The visibility setting part looks ok.  Without knowing what you have already tried, my suggestion would be to test whether mybut.Checked ever returns false.  I'd suspect that it is always returning the default true condition and not persisting the false setting once your code is finished executing.
0
Princy
Top achievements
Rank 2
answered on 30 Jul 2008, 12:00 PM
Hello Ilija,

You can try the following code snippet to toggle the visibility of a column on button click.

cs:
protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e) 
    { 
        RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").Visible = !(RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").Visible); 
        RadGrid1.Rebind(); 
 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Ilija
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or