|
Pete O'Hanlon wrote: As you can see, calling this method removes the need for a switch altogether.
Not if you have legacy code as the OP does. He still has to switch the code to the new method.
|
|
|
|
|
Augh... that's terrible.
|
|
|
|
|
Hi Pete, I like your solution, it looks short and effecient, however, there's still one big problem.. I cant understand it
See, I have this statement:
foreach (DataGridViewColumn grdC in grd.Columns)
{
switch (grdC.HeaderText)
{
case "ID":
grdC.HeaderText = "id";
break;
case "NAME":
grdC.HeaderText = "name";
break;
...
}
}<pre>
<div class="ForumSig"><hr><font face="Comic Sans MS" size="2" color="#3300aa">All generalizations are wrong, including this one!</font><font face="Arial" size="4">
(\ /)
(O.o)
(><)</font></hr></div>
|
|
|
|
|
your code is a WTF! All you're doing is lower-casing the header.
This would suffice
foreach (DataGridViewColumn grdC in grd.Columns)
{
grdC.HeaderText = grdC.HeaderText.ToLower();
}
|
|
|
|
|
|
The only place where there's a better solution, is where your switches indicate you should have a collection of classes, each representing a different case with the same overloaded method.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
i know know how to hide them that's not the problem. The problem is
my form is like this:
--------info--------
[ ]
--------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.
|
|
|
|
|
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;
int top = 10;
int left = 20;
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);
top += lineheight;
}
}
|
|
|
|
|
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...
|
|
|
|
|
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.
|
|
|
|
|
Ah, I see! Thanks Deresen, that will be handy to know!
|
|
|
|
|
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,' ','');
Or in the forms
YourTextBox.Text = YourTextBox.Text.Replace(" ","");
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
thanks guys for the help. It was gladly appreciated
Ferron
|
|
|
|
|
Hello guys I have a data transfer class in which among all the code in it i have created 2 events. in the envent handler of the event DownloadBegin im running a new form. The code below demonstrates what im doing.
//Events
public event delegateNull DownloadBegin;
public event delegateNull DownloadFinished;
//Event Handler
private void btnListenforConnections_Click(object sender, EventArgs e)
{
//Start listing for incoming connection from client applications
transfer.StratListiningForIncomingConnections();
lblincomingconnection.Text = "Listening for incomming connections";
transfer.DownloadBegin += new Transfer.delegateNull(transfer_DownloadBegin);
}
void transfer_DownloadBegin()
{
frmDownloadDataProgressBar progressbar = new frmDownloadDataProgressBar();
progressbar.Show();
}
The problem is when the form is being displayed it gets stuck for some reason.
|
|
|
|