|
In article, you suggest to use Control and the property as generic parameter.
But Control is the base class.The common property is only Text for all controls.
But in case of specific properties of a control,how can use generic method.
Suppose DataGridView.Rows[2].Cells[3].Value-how can use Control?
Because Control.Rows does not exists.
So if I need to update or access 3 controls 2 properties,
then have to write 6 delegates and 6 functions to do the job?
|
|
|
|
|
Actually I already answered that; here is one way:
public void SetCount(int count) {
dataGridView1.Invoke(new MethodInvoker(delegate() {
StatusBarLabel1.Text = "Checking PowerStatus " + count;
dataGridView1.Rows[2].Cells[4].Value = count;
label1.Text = Convert.ToString("Cnt "+count);
}));
}
|
|
|
|
|
Thanks for your replies Luc Pattyn.
Here you only use dataGridView1.Invoke,
but update other controls also.Is that ok?
|
|
|
|
|
poda wrote: Is that ok?
Yes. I told you before:
all those Control.Invoke calls are equivalent anyhow, they all send the delegate to the main thread, no matter what they do to which Control.
And you're welcome.
|
|
|
|
|
Required reading, if you ask me.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Would you please kindly refer me some links.
|
|
|
|
|
I do not understand why this will not compile. I have used it in other programs but I must be missing something here.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace mfwmp
{
public partial class Form1 : Form, IMessageFilter
{
public Form1()
{
InitializeComponent();
Application.AddMessageFilter(this);
}
}
}
|
|
|
|
|
Well the PreFilterMessage() Method has been part of the interface since at least .Net 1.1.
It would be a pretty weird interface if it had no methods or properties.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Read the error message. You created a class that inherits from Form and IMessageFilter , but you never provided an implementation for IMessageFilter.PreFilterMessage(...) .
|
|
|
|
|
Thanks got it fixed with your help. Stupid me. I assumed the minimal code should have compiled.
|
|
|
|
|
Hi George,
electriac wrote: public partial class Form1 : Form, IMessageFilter
when you promise to implement some interface, you must do so. Hence:
- either drop the IMessageFilter in that line;
- or provide all its members; that would be bool PreFilterMessage(ref Message m) { ... }
Cheers,
Luc
|
|
|
|
|
Hi all,
I was learning yield operator. And made a function like this.
public IEnumerable<Guid> GetIds(int count, DateTime time)
{
Console.WriteLine("Start");
{
if (DateTime.Now > time)
yield break;
else
yield return Guid.NewGuid();
}
Console.WriteLine("End");
}
But End never get printed.Can anyone tell why? Because after break statement it should get out of the loop and print it.
|
|
|
|
|
(what loop?)
yield break does not break out of a loop, it "signals the end of the iterator", or as msdn also says:
"In a yield break statement, control is unconditionally returned to the caller of the iterator"
Source: http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx[^]
|
|
|
|
|
From the relevant MSDN page for break :
The break statement terminates the closest enclosing loop or switch statement in which it appears. Control is passed to the statement that follows the terminated statement, if any.
So break breaks out of loops and switch statements. I am guessing that in this case it breaks out of your method.
Same for yield :
Used in an iterator block to provide a value to the enumerator object or to signal the end of iteration.
Once again yield is meant to be used in an iteration. if is not strictly speaking an iteration, although I suspect that your else block would run.
The pages I looked at did not say what these statements do when not used in iterations.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Because you terminate the method before you get there.
|
|
|
|
|
Thanks to all for answers.
I got the point. Whenever we write yield it returns IEnumerable to the caller.And once yield statement get executed, no statements get executed.
Thanks again..
|
|
|
|
|
One thing - when you built the code, did it not warn you that an unreachable condition had been detected? It's important to pay attention to warnings as well.
|
|
|
|
|
Pete O'Hanlon wrote: did it not warn you that an unreachable condition had been detected?
I am using VS2008 and there was no warning.
|
|
|
|
|
I find that surprising. Certainly, in VS2010 there is a warning - check to make sure that you haven't deselected the warnings checkbox.
|
|
|
|
|
Pete O'Hanlon wrote: Certainly, in VS2010 there is a warning
If I had had VS2010, I would've checked in VS2010. But in VS 2008, there is no warning for this.I got warning for something else(just to check, whether it is showing warning or not)
And if it is showing warning in VS2010, then might be a Bug in VS2008
|
|
|
|
|
No warning in VS2008 Express Edition (warning level = 4).
|
|
|
|
|
It seems to be a problem with it being in the if block - put it outside and it warns, inside and it doesn't - but it should.
|
|
|
|
|
I agree, however I'm not surprised they did get it wrong at first: yield return statements are not really breaking program flow like regular return s would (they somewhat resemble a UNIX fork), however yield break does break the flow.
|
|
|
|
|
Indeed, which is why I'd have expected yield break to throw a warning.
|
|
|
|
|
Hello everyone,
Currently I am building in my company system that includes all the scripts that coordinate them.
all so you can run scripts only from people Aspcfeim will only permissions.
Anyone ever built something like this? Does anyone have suggestions?
This course will build on WPF C #.
Thanks,
|
|
|
|