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

Hide textboxes

6 Answers 875 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mercell
Top achievements
Rank 2
Mercell asked on 20 Jul 2007, 07:51 AM
Hi,

I have a report with some textboxes where some functions as labels and other as datafields. I wan't the labels and datafields only to be shown if the datafield contains data.

Lets say I have a labelDescription and a textBoxDescription. If the Text of the textBoxDescription is an empty string I wan't to hide both the textBoxDescription and the labelDescription. I have managed to hide the textBoxDescription by implementing it's ItemDataBound event and setting it's Visible property to false if it doesn't contain any data but I can't figure out how to hide the labelDescription.

I tried setting the Visible property of the labelDescription to false but that doesn't seem to work. Here is my code:

private void textBoxDescription_ItemDataBound(object sender, System.EventArgs e)  
{  
    Telerik.Reporting.Processing.TextBox textBoxDescription = (Telerik.Reporting.Processing.TextBox)sender;  
 
    if (textBoxDescription.Text == "")  
    {  
        textBoxDescription.Visible = false;  
        labelDescription.Visible = false;//This doesn't work  
    }  

How do I hide the labelDescription?

Thanks

6 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 20 Jul 2007, 10:42 AM
Hi Bo,

In order to hide the labelDescription TextBox, you need to attach to the DetailSection's ItemDataBound event. Then, when you have a reference to the concrete processing "counterpart" of the DetailSection, you can search its children by name.

When you find the two TextBoxes you can adjust their settings as needed. Here is a code snippet that demonstrates this:

        private void detail_ItemDataBound(object sender, System.EventArgs e)
        {
            Telerik.Reporting.Processing.DetailSection procDetail = sender as Telerik.Reporting.Processing.DetailSection;
            Telerik.Reporting.Processing.TextBox procTxtColor = procDetail.Items["txtColor"] as Telerik.Reporting.Processing.TextBox;
            Telerik.Reporting.Processing.TextBox procLblColor = procDetail.Items["lblColor"] as Telerik.Reporting.Processing.TextBox;
            if (string.IsNullOrEmpty(procTxtColor.Text))
            {
                procTxtColor.Visible = false;
                procLblColor.Visible = false;
            }
        }

The important thing to remember is that when you are inside an event handler, you are not working with the original item definitions (instances of classes in the Telerik.Reporting namespace), but with their run-time representatives (instances of classes in the Telerik.Reporting.Processing) namespace. There is one item definition (the thing you see in design-time) and many run-time objects, for example there will be as many Telerik.Reporting.Processing.DetailSection's as there are rows in the data source.

I am attaching a little project which demonstrates the goal that you want to achieve.
 

Best wishes,
Rossen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Phil
Top achievements
Rank 2
answered on 26 Aug 2007, 03:41 PM
I may be misreading your question, so ignore me if that's the case, but isn't this as simple as setting the value of the "label" with a conditional?

=IIF(MyBoundData='','','My label')
0
Rossen Hristov
Telerik team
answered on 27 Aug 2007, 01:51 PM
Hi Phil,

Setting the Value of a TextBox to an empty string will not cause it to become invisible, so that will not solve Bo Jørgensen's task. The only way to make a report item invisible is by setting its Visible property to false.

 
Greetings,
Rossen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Phil
Top achievements
Rank 2
answered on 27 Aug 2007, 05:28 PM
Well this is what I do in my report, and it appears to be working, so I'll have to keep my fingers crossed that whatever magic is making the labels disappear continues to do so!  ;)  Perhaps it's because I also allow the fields to shrink? They may not be invisible, but they aren't taking up any space on the report.
0
Rossen Hristov
Telerik team
answered on 28 Aug 2007, 07:14 AM
Hi Phil,

We are glad that you have found a way to achieve what you need and it works perfectly in your particular case. CanSrink plus empty text makes the TextBox seem invisible, but de facto it is not. If it had a border for example, you will still see it.



I am attaching a very simple report demonstrating the two approaches. Everyone can use the approach that best suits his/her need.

Greetings,
Rossen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Phil
Top achievements
Rank 2
answered on 28 Aug 2007, 07:23 AM
Thanks for the explanation, I see the difference.
Tags
General Discussions
Asked by
Mercell
Top achievements
Rank 2
Answers by
Rossen Hristov
Telerik team
Phil
Top achievements
Rank 2
Share this question
or