|
Hi,
I have the following hardcoded labels:
this.labelAWeekAgo1.Text = lastWeek.ToString();
this.labelAWeekAgo2.Text = lastWeek.ToString();
..
this.labelAWeekAgo10.Text = lastWeek.ToString();
with each individual label contained within a loop that contains a function with the result generating "lastweek".
How can I code the label variable that changes programatically ie the number at the end of the labels name depending on which pass thru the loop I'm in eg
for i=0 etc
this.labelAWeekAgo[i].Text = lastweek.ToString();
Glen Harvy
|
|
|
|
|
Use For loop
for(i=0;i<9;i++)
{
//your code
}
or you can use foreach which is more easy.
Details[^]
Regards,
Satips.
|
|
|
|
|
Thanks for the prompt reply.
I'm trying to avoid having to do the following for each hardcoded label:
Label[] lbThisWeek = new Label[10];
for (int i = 0; i < lbThisWeek.Length; i++)
{
lbThisWeek[i] = new Label();
}
lbThisWeek[0] = this.labelThisweek1;
lbThisWeek[1] = this.labelThisweek2;
lbThisWeek[2] = this.labelThisweek3;
lbThisWeek[3] = this.labelThisweek4;
lbThisWeek[4] = this.labelThisweek5;
lbThisWeek[5] = this.labelThisweek6;
lbThisWeek[6] = this.labelThisweek7;
lbThisWeek[7] = this.labelThisweek8;
lbThisWeek[8] = this.labelThisweek9;
lbThisWeek[9] = this.labelThisweek10;
Doing this allows me to use the loop to perform my actions but it seems I have to create separate arrays for each item as I can't see how you pass [i] to a hardcoded control name.
Glen Harvy
|
|
|
|
|
Hi,
create a collection of your labels (an array, an ArrayList, a List, whatever),
and foreach them.
If its all the labels on a form, you could also foreach your form's controls as in:
foreach (Control c in myForm.Controls) {
Label lbl=c as Label;
if (lbl!=null) doSomethingToLabel(lbl);
}
Finally you could use reflection to find all the labels with a specific name syntax,
but that seems overkill (and expensive) in this case.
|
|
|
|
|
Thanks,
Yes - it looks like an array for each label concerned is the easiest - thank heavens for search & replace.
Glen Harvy
|
|
|
|
|
Ho ho, I think no one suggested changing the label names; if you replace myLabel1 by
myLabel[1] the Visual Designer will no longer understand it (the declarations would
be wrong).
What you should do is keep the labels as they are, and on top of that create a list
(an array or some other collection) that holds references to them, so you can foreach it.
You could create and populate the list right after the call to InitializeComponents().
|
|
|
|
|
Create an array of references to your labels:
Label[] labelAWeekAgo = new Label[] { labelAWWeekAgo1, labelAWWeekAgo2, ... ,labelAWWeekAgo10};
Note that the index for the array is zero based.
If you use foreach to loop the array, you don't use an index:
string lastWeekString = lastWeek.ToString();
foreach (Label label in labelAWeekAgo) {
label.Text = lastWeekString;
}
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi All,
I have developed a windows application using serial port.
Now, i am asked to convert it into a .exe file(console application)..Is it possible? if so, how can i do it??
could any one please help me...
Thanks in Advance.
|
|
|
|
|
Just create a console app and move your code into it. The main thing is, a console app does not have events, so you need to build your own menus and so on in plain text.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have done it in the same way...
ITs running well on my machine... But when I run that .exe file on another machines its saying
" application failed to initialize properly: Click OK to terminate the program"
whats the problem??
how can I run my .exe on another machines as well....???
|
|
|
|
|
There can be several reasons for this, try Google to see them.
Best guess is read access violation on some DLL file.
BTW the message typically includes an error code, if it did you should show it.
|
|
|
|
|
please give me code for create an child(already designed) form with in mdi form
|
|
|
|
|
We cannot do your work.
What you have done so for and what error it shows tell us that i have done this but i am getting this error.
Regards,
Satips.
|
|
|
|
|
It's a pretty straightforward question, probably just one function call to do it. I'd answer it, if I knew.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
private void categoryToolStripMenuItem_Click(object sender, EventArgs e)
{
empCat cat = new empCat();
cat.MdiParent = MdiParent;
cat.Show();
}
this is the code tell me the correct code where mdiparent is a form name cat is a object of empCat ( which i want to make a child of Mdi Parent Form).
Please Provide me Correct Code
|
|
|
|
|
this is the answer
empCat cat = new empCat();
cat.MdiParent = this;
cat.Show();
|
|
|
|
|
Sir, please explain further for a clearer pictures.
Dabsukol
|
|
|
|
|
|
It is because on your postback your datagrid will always be one step behind. I have had the same problem many times, the fix for it is to find what event you need to fire after and it changes for different situations, usually OnPreRender works. iam writing like this
protected override void OnPreRender(EventArgs e)
{
dg1.CurrentPageIndex+=1;
base.OnPreRender(e);
}
private void PreRender_Handler(object sender,System.EventArgs e)
{
dg1.CurrentPageIndex = Convert.ToInt32("");
}
by giving like this iam getting even records but not odd records.
srinivas
|
|
|
|
|
I have a form with report viewer control, it displays the report fine and all other toolbars works just fine except when I click Find (after entering a text of course), the reports return error "Object reference not set to an instance of an object".
All I did is just very simple, created a form, add the reportviewer control in the form, create a report (.rdlc), specify the datasource, and the report prints fine, it is really giving error only in Find text.
How do you correct this?
And what may have cause this error?
Your help is very much appeciated.
Thanks.
|
|
|
|
|
Do any experts here have a great idea on this issue?
Please help and let me know if you need a sample project so you can see and replicate this issue, then I can send it to you.
Thanks in advance.
|
|
|
|
|
I have a web page that can be access by multiple users at the same time.
My problem is that when the 1st user access the first record to process it, the 2nd user has also the priveledge to access and process it at the same time with the first user. Until the 1st hasn't clicked the process button anyone can see and modiy the record.
How can I block the 2nd/3rd user from processing the record that is already opened by 1st user?
How can I implement locking to inform the user that a certain record is already being processed by the 1st user since after retrieving the record from the database I am already disconnected..
Please give some advice since most of our web page has the same process. Tracking System per group.
Dabsukol
|
|
|
|
|
I have implemented concurency a while ago using TimeStamp fields.A TimeStamp are modified everytime a change is made to a record that contains such a field.Then you use the TimeStamp value in evey update query where concurency is an issue to ensure that the data has not been changed, for example:
<br />
<br />
UPDATE MY_TABLE<br />
SET SOME_FIELD= @SOME_VALUE<br />
WHERE ID = @SOME_ID<br />
AND TimestampID = @TimestampID<br />
|
|
|
|
|
Your rows need a 'locked by' column, which takes a user id. If it's not null, or a 'magic number', then it's locked. You probably also want to store the date/time it was locked, because you probably want the locks to automatically time out, otherwise, your system will fail if a user doesn't perform the action that unlocks it again.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank you, we have the same thing in mind but can you provide code for my problem?
Dabsukol
|
|
|
|