how to overflow text in excel C#/VB.Net - c#

I need to overflow text of a cell that has too much data. I can't easily split it up into multiple cells so I guess the only choice now is to overflow it, but I just cant seem to find a way to do it.
wb.Cells(1, 1) = bigstring
wb.Cells(1, 1).WrapText = True

If your problem is that they aren't displaying in the cell it is because the amount of characters displayed is cut off after 1024 characters. The value is still stored and you can see up to 32k characters in the formula bar.
wb.Cells(1, 1) = bigstring.Substring(0, 3276)
stringHolder = bigstring.Substring(32767)
Will store any leftovers that are too big for your cell to hold. I'm not sure if this is what you mean by "overflow" but it should let you handle any data that is too big to fit in a cell.
Another solution might be to add the large string to a comment box on that cell, so users could see the whole thing when they click on it without having to look at the formula bar

Related

Microsoft ReportViewer: Customize Y-Axis labels to match a specific format

I would like to customize the Y axis labels of a graph plotted with Microsoft ReportViewer.
What I want is to have a logic like the following:
If (value>1000000)
return value/1000000 & "M"
else
return value
For example if the value of the label is 12000000 then the label value will be 12M, otherwise if the label value is 1200 the value will remain 1200.
I have tried to customize the numeric format to obtain this kind of behaviour tring something like:
= iif(value>1000000,value/1000000 'M',value)
(to help contextualize my question, i'm talking about this window=> https://dotnetblurb.files.wordpress.com/2012/05/3.jpg)
but, as expected, it didn't work.
Googling didn't help much as well, it seems like this kind of customization is just not possible. Or is it?
Thank you very much!
I solved this issue using both the expressions window and altering the graph's datasource content.
In the method filling the data source I added the logic converting big numbers into smaller numbers:
reportModel.MillionsSymbol = "";
if (reportModel.TotalValue > 1000000)
{
reportModel.TotalValue /= 1000000;
reportModel.MillionsSymbol = "M ";
}
I also added the new MillionsSymbol field to my data source and I change its content based on the TotalValue.
Then, I can use this new field in the dialog Vertical Axis Properties -> Number -> Category[custom]
="0.00" & Fields!MillionsSymbol.Value
The trick here is that I wrote an expression that is returning a string containing the characters mask needed by the function that is formatting the axis numbers' label. In this string I can put anything as long as it contains the mask (0.00, #.##,...).
This method allows me to concatenate a variable to the value that is going to appear as a label for every tick of the vertical axis of the graph. It doesn't allow me to work on that value, since I didn't find any way to get access to it. This is why I altered the values in the data source. In this way, though, I'm changing the value of the graph points and then conseguently the vertical axis ticks' values.
Final result:
*Image edited for clarity

Limiting size of input to the size of a TextBox in C#

I've seen quite a few questions about scaling a TextBox to the size of the text, but only found a single question which talked about the reverse here. That question is also from 2010, and I believe the language has evolved since then, and there might be better solutions.
I'll clarify that I do not want to limit my input to an arbitrary number of characters, as the input may include newlines/vertical space. (Which, if it contained a lot of vertical space, could stretch the text beyond the bounds.)
Here's the situation:
Form 1 has a textbox. I want this textbox to remain a fixed size. Any data beyond the size should be cut off from the input.
I want to save Form 1's textbox's contents to a file.
In Form 2, I want to open the file and pull what was Form 1's textbox's contents. These will be saved in a separate textbox local to Form 2.
My strategy right now is to find a way to limit the input to the dimensions of the textbox, so that the textboxes in Form 1 and Form 2 are equivalent, and do not overflow their respective dimensions.
So my question is: How would I go about doing that?
Edit: Sorry, it appears my question didn't provide enough information. I also mis-typed the situation, so I'll re-write it below.
I'll step back and describe more of what I'm trying to do.
Let's assume I have a single Form, with the following two objects:
Textbox
Label
Anything I type into the Textbox I want to see on the Label's text. Input can be any letters, numbers, or special characters, including spaces and newline characters.
For the sake of consistent sizing, I want the label to be of a fixed graphical size; regardless of the number of characters in the label's text, the label object should be no larger than (x, y), where x and y are arbitrary height and width sizes.
I do not want data in the Textbox that cannot fit within the bounds of the label's size. The user should be prevented from entering data into the Textbox that would extend beyond the label's size bounds.
Are there any strategies not mentioned in the linked question that can determine whether a Textbox's text meets or extends past an arbitrary width and height?
The properties of the textbox give you a max length, you can also do it in code like so
var tb = new TextBox();
tb.MaxLength = 10
if you don't want to use that then you should use
var str = tb.Text.Remove(0, 10)
this will only give the str variable the first 10 characters no matter the length of whats actually in the textbox.
For what you want on form two, you need to give me more information about what you want.
edit after OP's edit
if you want the text in the textbox to be matched at the label level you want add a TextChanged Event to the property of the textbox and then have something like this
private void TextChanged(object sender, EventArgs e)
{
label1.Text = textBox1.Text;
}
having the label to a fixed size no matter what is isn't going to be good, ive done it, but this also begs the question, why are you duplicating your textbox information into a label. Why not just have it in a textbox

How to set a min width before word-wrap inside an Asp.net Grid View column iif that columns text is at least certain length. ex 50 words

...without knowing how many columns the grid view may have or which columns will contain a lot of text. (Auto resize all other columns)
I have a grid view on a webpage that is generated from a database and it displays different columns in different orders depending on the user or user groups. Typically, it is displaying somewhere between 15 and 30 columns. For some user/user groups all of the columns can fit on the screen without any text wrapping too much, for others even after the grid view auto sizes all of the columns to be as small as possible it doesn’t all fit on the screen requiring a horizontal scroll bar and it’s then forcing the columns with large amount of text to wrap after only one or two words.
I am trying to figure out if there is a way to stop a column from resizing to a tiny size if its content is really long and instead wrap only after a certain size (assuming that the content of that column is large enough to require the column to be that “certain size” to begin with) however I can’t know which column is going to have a ton of words since each user / user group can modify which columns they use, which are displayed, and what each column is called. (So I can’t hard code a specific column to be a minimum/specific width)
Example
If for example a column has text that is long than say, 50 words, I want to set that column to only word wrap after at least 4 or 5 words have already been displayed on the first line (or a certain pixel size) But if a column is smaller than that I want the column to become as small as possible so that as many rows / columns can be visible on the screen as possible. I don’t mind the horizontal scroll but I am trying to get the wrapped text to not wrap more than 5 or so lines. (Currently it’s wrapping like 15-30 lines leaving 1 -2 words on a line)
Example – What I want
UserGroup1
This is what I would like to happen (The column with the long text is kept large enough to read multiple words before wrapping
Example -- What I’m currently getting
UserGroup1 (This only happens to users groups who have a ton of columns, other user groups are able to fit everything on the screen without ridiculous word wrap)
Example of what I'm currently getting -- Row with lots of columns is word wrapping every word or two causing the row to take up ton of space on the site. (Made image a bit smaller since its so tall)
This User/User group also has so many columns set to display that it has a horizontal scroll making it difficult for users to get to easily read the data.
Additional Example
Example of a different user group who has less columns and a different order.
Description
This is an example of a different user/user groups gridview display. This user/user group has chosen to have a lot less columns and all of the columns have no problem fitting on the page. This gridview does not have a horizontal scroll bar and already wraps nicely due to less columns.
This grid view automatically resizes the smaller columns and makes the column with more data bigger because it doesn’t need to try to fit a ton of columns on the page. This example is similar to the "What I want" example, except it has less columns so the description column is wider.

Why is text disappearing in RichTextBox?

I'm creating a flat file reader (simple hex editor if you will) in c# using RichTextBoxes. One RTB shows the hex values and another shows the ASCII values.
My plan is to show one 'record' per line. So, if there are 10 records I want to look at with a length of 1000, there will be 10 lines of 1000 characters per row in the ASCII and the hex side will have a length of 3000.
I dynamically set the rtb.RightMargin property to the length of one record.
The problem I'm running into is when the records are incredibly long, over 3500 chars for the ascii side making the hex side very large, I find that the text starts to disappear in the middle and end of the records when the right margin becomes too large. So for example:
hexRtb.RightMargin = 7500 //This is because it's triple the size of the ascii text.
In the hex rtb, it'll show the first parts of the text until I start scrolling towards the middle where all text stops showing completely. If I manage to click on these empty parts of the record, text will show up, but then disappear again after scrolling away.
I cannot figure out what's going on. This only seems to happen when the RightMargin is set to an incredibly large number. Smaller numbers, all text will shows without a problem.
Anyone ever encountered something like this?
Here's a code sample if it helps.
int asciiRecordLength = mHexReader.RecordSize;
int hexRecordLength = mHexReader.RecordSize * HexByte; //This is to convert the ascii record length to a hex record length
asciiTextBox.RightMargin = TextRenderer.MeasureText(mHexReader.GetAsciiValues().Substring(0, asciiRecordLength), asciiTextBox.Font).Width;
hexTextBox.RightMargin = TextRenderer.MeasureText(mHexReader.GetHexValues().Substring(0, hexRecordLength), hexTextBox.Font).Width;
//Populate text boxes
hexTextBox.Text += mHexReader.GetHexValues(); //This gets all of the records to be read
asciiTextBox.Text += mHexReader.GetAsciiValues();
For those who've run into the same problem I have, I found a workaround to this problem.
Instead of using RichTextBox, I found another control you can download called ScintillaNET. So far, I've been able to switch over most of my code to using this control without any problems. Some of the functions are slightly different, such as, instead of hextTextBox.Clear() it's hexTextBox.ResetText(), or hexTextBox.SelectionStart is now hexTextBox.Selection.Start.
Minor differences but this control fixes the issue with the pixels disappearing when the record length becomes very large.
The code can be downloaded from: http://scintillanet.codeplex.com/
Hope this helps anyone else who has run into the same problem I have.

Drawing formatted text

I set up a draw rectangle to draw simple formatted text first aligned to the left as
*item 1
[1]Something
content
[2]Something else
<a> subsomething else
content
<b> another subsomething else
content
*item 2
The end.
and I would also like it to automatically create a new column (after checking for the longest string in the first column [drawn stuff on the left hand side]) to draw the rest into it.
In order to keep track of the paddings and itemized sections and subsections, I think of using a stack which I can push and pop the current and next positions needed to draw a text line each time I leave a content. Yet, I can't figure out how to jump back to a certain subsection position because stack doesn't offer an inline sub-scripting method.
Then I look into a hash-map (in C# I have tried Dictionary) to keep track of it and to access the value via specific key. For that I also use a external global variable to maintain the number of subsections the user may have entered and increase one each time a new subsection is created; and the float value is used to store the x-coordinate value for the drawstring to be done. This is complicated to me at least at present when I don't really have a nerve to go into it anymore. I can only receive false simulated outcomes.
So I am asking for an easier approach to tackle this problem, which I think is simple to many of you sure experiencing the same situation. I am desperately looking forward to seeing a short easy method to do this.
Draw formatted text using ..
..whatever works. I suggest a JLabel, which will render (simple) HTML/CSS formatted content.
See LabelRenderTest.java for an example.

Categories