|
Why not just send the strings directly, without assigning to a variable?
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Skippums wrote: Why not just send the strings directly, without assigning to a variable?
ahahahahahah
that's right, that would solve it.
But that example is just an illustration of my problem. The actual code gets the contents from somewhere else dynamically, and it doesn't display a message box, it does something else... this was just to simplify. I actually solved this by moving the value holder inside the context, and this way, a new reference is always created.
Gonçalo A.
|
|
|
|
|
Kensho wrote: The actual code gets the contents from somewhere else dynamically...this was just to simplify
Exactly... that is why Dave asked you for more specific code. Clearly, you would have thought of this if it solved your problem; however, in your example this is a valid solution. Try to be slightly more specific in your problem statement so we can give "real" feedback instead of having to guess what the problem is. Glad you got it working,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Ok... the thing is... I had solved it since I posted the first message here.. I said it even... I only spoke about the positioning of the variable and the association to runtime delegate.
This is que only thing that I questioned:
Kensho wrote: Now... can anyone explain me why does this happen? The delegate uses the reference instead of the value?
delegate... value... I don't understand why the big fuss over a simple question.
But nevermind... I already got my answer... maybe someone can pick this up and find it useful, as a simple piece of information, as it is.
Cheers
Gonçalo A.
|
|
|
|
|
One word : closures. A closure captures the value of a variable in its lexical scope.
Your event handlers are anonymous functions which capture the local variable text . Behind the scenes, the compiler generates a new class with the captured variable as a member and rewires the event handler so that it calls a method on the generated class. That class then uses the member variable's value to fill in for the captured variable.
The compiler updates the generated class instances with the value of captured variables as long as the captured variables are in scope. In your case, text was declared outside the scope of both if blocks, so the compiler dutifully updated the value of the variable when you changed it inside the second if block.
Just to make things clear, this is not done only for reference types (like string).
delegate void Func();
static void Main()
{
Func[] f = new Func[10];
for (int i = 0; i < 10; ++i)
{
f[i] = delegate { Console.WriteLine(i); };
}
foreach (Func func in f)
{
func();
}
}
This will print 10 all ten times.
|
|
|
|
|
Exactly!
Now that's an answer. Thank you.
Cheers
Gonçalo A.
|
|
|
|
|
hi frein i multiple text boxes in my form and i want tpo highLight Text box when tab Control reach to specific Text Box but when Tab Control Leaves it come back to its Orignal Place
how can i do that
wasim khan
|
|
|
|
|
Do you want to?:
1. Highlight the text that is currently in the text box as the user enters the control.
2. Set the background color of the text box as the user enters\exits the control.
If the answer is 1:
Handle the Enter event for the textbox and then call textbox.SelectAll();
If the answer is 2:
Handle the Enter event for the textbox and set the textboxes Appearance.BackColor property.
Handle the Leave event and set this same property back to its original value.
If its neither then you will need to explain again what you were asking.
I hope this helps.
|
|
|
|
|
you can use Textbox.Focus() methods and Textbox Leave Events and Changes the background color according it !!!
|
|
|
|
|
Hi all,
This is my first C# application. Here what I going to do.
Read a text file and display them in a list view. Simply as line by line. I can read the file and get line by line there easily. My question is how to display them.
Any tutorial you guys know that I can get a better start.
I appreciate your help all the time...
Eranga
|
|
|
|
|
listviewControl.Items.Add("string from file");
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Yes I do,
But I have one question now. I read a file and found those lines to put into list view. A line consist of four words and in between each word there is a tab character. For tabs, on list view display some annoying characters. I put a message box and test at the time I got the line of text. It's ok, no printed and tabs.
How can I avoid it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
value.Replace('\t',' ');
This replaces all occurences of tabs with a space.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Thanks, but what I have done is that, use tab as a delimiter and get substring from the original string.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Hi Friends,
I have developed a Windows service. Now i need icon for this service in
systray and context menu for this icon.
I have added context menu for notify icon but context menu not displaying in systray.
Please let me know how to do this?
With regards,
Dharani.
|
|
|
|
|
dharanighanta wrote: Hi Friends,
I have developed a Windows service. Now i need icon for this service in
systray and context menu for this icon.
I have added context menu for notify icon but context menu not displaying in systray.
Please let me know how to do this?
AFAIK, it won't display. A service is supposed to run without any user interaction. I.E. no System.Windows.Forms . I think you can have the tray icon, but no context menu. Maybe someone will verify this. What I think you will have to do is have your service start a process that is nothing but a tray icon, with the context menu(if that's what you want), and then have that application communicate with the service.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
|
You can't easily do it. It's as simple as that. If you could, this would represent a huge security hole whereby you could get really malicious with the user without them knowing. There's a reason that people switch off cookies and it's really bad practice to try to circumvent that.
|
|
|
|
|
bachirium wrote: But i can't ask every user to enable cookies
Yes you do have to ask. Period.
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
How can I show table into 2 columns - one half of data in the first and other half in the second column in Crystal Report?
In Visual Studio Local Report it's accomplished by setting Report's Body Columns on 2.
Example:
||| => ||| |||
||| => ||| |||
||| => ||| |||
|||
|||
|||
Thanks for any help.
modified on Friday, January 11, 2008 5:30:33 AM
|
|
|
|
|
Hi
I have a sql statement which is in my c# code.
How would I write the following though
Select * from table where field contains a certain value
e.g. select these values from the table
v1106~066
v1106~066_01
where as at the moment it just selects:
v1106~066_01
my current sql statement is select..... LIKE '" + s_number + "'" +
s_number is the value v1106~066_01
thanks!!!
hope it makes sense
|
|
|
|
|
sorted it:
"'+ session_room_code + "%'"+
|
|
|
|
|
In order to match against multiple records, you need to apply the wildcard characters in your search. In other words, you need to use v1106~066% to retrieve the two records. A couple of thoughts though.
1. You shouldn't retrieve all of the columns using *. That's just lazy coding and should be avoided at all costs.
2. You've left yourself wide open to a Sql Injection attack. Read this[^] article.
|
|
|
|
|
I'm not actually using Select * i just put it there becasue I couldnt be bothered to write out all of the fields i was selected which ironically makes me lazy
|
|
|
|
|
Jamie1985 wrote: I'm not actually using Select * i just put it there becasue I couldnt be bothered to write out all of the fields i was selected which ironically makes me lazy
OK. Nice one.
|
|
|
|