views:

555

answers:

2

Can a textbox's width in a local RDLC report be set dynamically using C#? I would like to auto size the horizontal width of the text box based on the data it contains.

A: 

Try this:

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        Graphics g = this.CreateGraphics();
        textBox1.Width = (int)g.MeasureString(textBox1.Text, textBox1.Font).Width+10;
    }
Oskar Kjellin
The problem with the above code is that I cannot access, or do not know how to access the textbox that is on a RDLC report. This isn't a standard textbox in c#, it's embedded in the RDLC report.
Zavior
Basically I need to access a matrix's textbox on the report at run time to determine the length of what it contains, then auto size that matrix column...if possible.
Zavior
Okay, what if you set both CanGrow and CanShrink to true?
Oskar Kjellin
CanGrow and CanShrink only effect vertical sizing, don't ask me why it was designed that way...
Zavior
A: 

Not easily. http://gotreportviewer.com/ has examples for how to generate the RDLC dynamically from C#. Alternatively, you can try to add a script to your report that does that. I am not sure that the size and coordinates are in fact writable properties, though. I suspect that they are read-only.

cdonner
Yea that's the answer I'm looking for, wither or not they are writable. I've looked into the reports LocalReport property for the textbox but can't seem to find anything.
Zavior
Look at the answers to this question. Using a ReportViewerHelper may allow you to do that:http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/c29e929d-573a-453e-8393-0f3e86065921/
cdonner