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
2010-03-22 18:17:43
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
2010-03-22 18:24:09
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
2010-03-22 18:25:51
Okay, what if you set both CanGrow and CanShrink to true?
Oskar Kjellin
2010-03-22 18:26:26
CanGrow and CanShrink only effect vertical sizing, don't ask me why it was designed that way...
Zavior
2010-03-22 18:32:55
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
2010-03-22 18:20:49
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
2010-03-22 18:36:30
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
2010-03-22 18:59:15