Hide textboxes

7 posts, 0 answers
  1. Mercell
    Mercell avatar
    33 posts
    Member since:
    Nov 2006

    Posted 20 Jul 2007 Link to this post

    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
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 20 Jul 2007 Link to this post

    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
  3. DevCraft banner
  4. Phil
    Phil avatar
    84 posts
    Member since:
    Apr 2005

    Posted 26 Aug 2007 Link to this post

    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')
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 27 Aug 2007 Link to this post

    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
  6. Phil
    Phil avatar
    84 posts
    Member since:
    Apr 2005

    Posted 27 Aug 2007 Link to this post

    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.
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 28 Aug 2007 Link to this post

    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
  8. Phil
    Phil avatar
    84 posts
    Member since:
    Apr 2005

    Posted 28 Aug 2007 Link to this post

    Thanks for the explanation, I see the difference.
Back to Top
DevCraft banner