Remove empty textbox spaces
-
I have written a code that fills a form with data from a database into textboxes, the thing is some of the textbox comes up with empty information and they leave gaps within my document, is there any way to get rid of them?
Ferron
-
I have written a code that fills a form with data from a database into textboxes, the thing is some of the textbox comes up with empty information and they leave gaps within my document, is there any way to get rid of them?
Ferron
Hey there, Lodeclaw was right, why don't you handle it while filling it "your database", anyways, you can use the DECODE function from the database
DECODE(ColumnName,' ',''); //Finds a space and replace it with an empty string
Or in the forms
YourTextBox.Text = YourTextBox.Text.Replace(" ",""); //Which does the same but at the form level
All generalizations are wrong, including this one! (\ /) (O.o) (><)
-
To clarify, are you filling a single textbox with more than one value from your database? Or do you have completely empty textboxes and want to format the empty spaces out of the form?
just one value for each text field. I have the address one under the other and there are making my page look bad. I want to format the empty spaces out
Ferron
-
just one value for each text field. I have the address one under the other and there are making my page look bad. I want to format the empty spaces out
Ferron
I'm no expert, so there's only one solution I could think of that would work:
if (textbox1.TextLength < 1)
{
textbox2.Location.Y -= [int HeightOfTextbox];
}I think the location 0,0 is in the upperleft corner, so this should be the right equation, but don't quote me on it. I haven't actually tested this.
modified on Wednesday, February 11, 2009 4:45 PM
-
I'm no expert, so there's only one solution I could think of that would work:
if (textbox1.TextLength < 1)
{
textbox2.Location.Y -= [int HeightOfTextbox];
}I think the location 0,0 is in the upperleft corner, so this should be the right equation, but don't quote me on it. I haven't actually tested this.
modified on Wednesday, February 11, 2009 4:45 PM
-
Hey there, Lodeclaw was right, why don't you handle it while filling it "your database", anyways, you can use the DECODE function from the database
DECODE(ColumnName,' ',''); //Finds a space and replace it with an empty string
Or in the forms
YourTextBox.Text = YourTextBox.Text.Replace(" ",""); //Which does the same but at the form level
All generalizations are wrong, including this one! (\ /) (O.o) (><)
thanks guys for the help. It was gladly appreciated
Ferron
-
Just for some extra info, you can do this slightly better: Use pre tags for instance. And do it like this:
if(String.IsNullOrEmpty(textbox1.Text))
{
textbox.Visible = false;
}visible doesn't remove the space there. jst don't show
Ferron
-
visible doesn't remove the space there. jst don't show
Ferron
-
He was commenting on the formatting of my post, but you should note how he set up his if-statement. :)
I was trying to move some the labels with the location.Y method but it doesn't seem to be working. Any help on how get rid of the empty labels as well?
Ferron
-
I was trying to move some the labels with the location.Y method but it doesn't seem to be working. Any help on how get rid of the empty labels as well?
Ferron
Use the visible property shown in Deresen's post to hide labels you don't want shown. The labels should be able to move the same as your textboxes.
if (String.IsNullOrEmpty(textbox.Text))
{
textbox.Location.Y -= textbox.Height;
label.Location.Y -= textbox.Height;
}modified on Wednesday, February 11, 2009 6:01 PM
-
Use the visible property shown in Deresen's post to hide labels you don't want shown. The labels should be able to move the same as your textboxes.
if (String.IsNullOrEmpty(textbox.Text))
{
textbox.Location.Y -= textbox.Height;
label.Location.Y -= textbox.Height;
}modified on Wednesday, February 11, 2009 6:01 PM
--------info-------- i want to remove the space created by the empty textbox/label or move it to another location where it doesn't take up spaceFerron
-
--------info-------- i want to remove the space created by the empty textbox/label or move it to another location where it doesn't take up space
Ferron
I understand. In theory I figured it would work to move the controls below the empty textboxes up to fill in the gap, however I can't seem to get it working. Hopefully someone a little more knowledgeable will swing by. In the meantime I'll try and figure it out myself and let you know if I come up with anything. I'm still a newbie, myself.
-
Use the visible property shown in Deresen's post to hide labels you don't want shown. The labels should be able to move the same as your textboxes.
if (String.IsNullOrEmpty(textbox.Text))
{
textbox.Location.Y -= textbox.Height;
label.Location.Y -= textbox.Height;
}modified on Wednesday, February 11, 2009 6:01 PM
Error 646 'System.Web.UI.WebControls.Label' does not contain a definition for 'Location' and no extension method 'Location' accepting a first argument of type 'System.Web.UI.WebControls.Label' could be found (are you missing a using directive or an assembly reference?)
That's the error is got when i tried using the Location.Y method
Ferron
-
Error 646 'System.Web.UI.WebControls.Label' does not contain a definition for 'Location' and no extension method 'Location' accepting a first argument of type 'System.Web.UI.WebControls.Label' could be found (are you missing a using directive or an assembly reference?)
That's the error is got when i tried using the Location.Y method
Ferron
Ah, I think I've figured it out. Read this: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.location.aspx[^] And you should understand why you have to do it like this:
if (String.IsNullOrEmpty(textbox.Text))
{
textbox.Location = new Point(textbox.Location.X,(textbox.Location.Y - textbox.Height));
label.Location = new Point(textbox.Location.X, (textbox.Location.Y - textbox.Height));
}Again, I think it should work but I could be wrong. Hahaha...
-
--------info-------- i want to remove the space created by the empty textbox/label or move it to another location where it doesn't take up space
Ferron
So you have this: line 1 line 2 line 4 and you want to have it like this: line 1 line 2 line 4 If I understand you well, you would like to have it is above. If that is what you want, you have to program dynamically. This is what I always do when it is about dynamic programming:
String[] myLines = {"line 1", "line 2", "", "line4"};
int lineheight = 23;//pixels between the labels
int top = 10;//align from top
int left = 20;//left align
int width = 200;
Label l;foreach(String myLine in lines)
{
if(!String.IsNullOrEmpty(myLine))
{
l = new Label();
l.Location = new Point(left, top);
l.Width = width;
l.Text = myLine;
this.Controls.Add(l);//this will only work if the class you're working in is a Control class like form
top += lineheight;
}
} -
Ah, I think I've figured it out. Read this: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.location.aspx[^] And you should understand why you have to do it like this:
if (String.IsNullOrEmpty(textbox.Text))
{
textbox.Location = new Point(textbox.Location.X,(textbox.Location.Y - textbox.Height));
label.Location = new Point(textbox.Location.X, (textbox.Location.Y - textbox.Height));
}Again, I think it should work but I could be wrong. Hahaha...
-
textBox.Location.X is the same as textBox.Left and textBox.Location.Y is the same as textBox.Top It's not that your code is bad, because it's the same. But it's a little shorter.