|
all the records are displaying twice or any specific record is displaying....
If all the records are displaying then the problem is in your database...
check the where condition in the database....
Padmanabhan
|
|
|
|
|
Try clearing dataset.
CC26
|
|
|
|
|
Hi all,
I have a class that performs some actions and calculations. Lets call it: class Calc
I also have a win form class called: class winForm
I want to set a label Text property on the win form from the Calc class.
How can I do this?
Many thanks in advance
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
The calc class needs a referene to the form, or, better yet, a delegate needs to be hooked up between the two classes, so that calc can fire an event inside the form.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: a delegate needs to be hooked up between the two classes,
A delegate just to set label text?
जय हिंद
|
|
|
|
|
A delegate is the only clean way to have communication between classes. Better that, a designated event, than passing reference to forms around and exposing text properties on labels.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
In this scenario, if Calc has only one instance thoughout and if that gets created in the form itself, then
a) would databinding the label text be enough?
b) still stick to delegates?
जय हिंद
|
|
|
|
|
Who cares... The entire point is that the non-form class shouldn't have ANY knowledge of the form using it. It should not have any reason at all to modify UI controls. What if the class needs to be used by another non-form class somewhere down thte road??
The correct way to do this would be to have the Calc class expose methods, events, or delegates, that outside consumer would subscribe, or otherwise wire-up, to receive notifications that the Calc class outputs. But, these would not be manadatory subscriptions to use the class. It should be left up to the caller to determine if it needs this notification information, not the Calc class.
|
|
|
|
|
Thanks for the response Christian.
You don't perhaps have any good links on the web referring to an example?
If not ... i do know how Google works ... just wondering.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
There are some good articles on delegates right here on code project, so search this site first, then google if you need to. I don't know off hand, but I know there's been a lot written about them.
You CAN just keep an instance of your form in your other class, but it's really ugly, delegates are the neat and clean way of doing what you want.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
|
Ever heard of Properties in C#?
जय हिंद
|
|
|
|
|
|
Sorry. I thought this is all that needs to be done.
जय हिंद
|
|
|
|
|
Class
class Class1
{
public void ChangeTextctl ( string text , System.Windows.Forms.Control ctl )
{
ctl.Text = text;
}
}
Form
Class1 cls = new Class1();
cls.ChangeTextctl("Test", button1);
Non related to the Above
P.S : if you want to change the control text from another form
then set the control modifiers as Internal . and call it from the instant
I know nothing , I know nothing ...
|
|
|
|
|
I think he wants to do it in the other direction. To do it in the direction you suggest, makes no sense at all.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Just a quick question:
When creating a new instance of the class by calling the constructor, wouldn't you re-initialize all of the controls again? InitializeComponent();
What if you don't want that to happen?
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
is the Calc class instanciated by a winForm class? If so, raise an event in your Calc instance (with a custom event args instance to pass the text), and subscribe to it in the winForm instance, and update the Label from the handler.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Dave,
Thanks for the response.
Is there any way you could give an code example, because that is more or less what is happening.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
This is a quickie example that should help to get you started. For more details on events, search this site, google... and have a look at my article Events Made Simple[^].
public partial class WinForm : Form
{
private Calc calc;
public WinForm()
{
InitializeComponent();
calc = new Calc();
calc.CalcResult += new EventHandler<CalcResultEventArgs>(calc_CalcResult);
calc.Add(3.14159265f);
}
void calc_CalcResult(object sender, CalcResultEventArgs e)
{
label1.Text = e.ResultAsString;
}
}
public class Calc
{
public event EventHandler<CalcResultEventArgs> CalcResult;
public float Value
{
get;
private set;
}
public void Add(float number)
{
Value += number;
OnCalcResult(new CalcResultEventArgs(Value.ToString()));
}
protected virtual void OnCalcResult(CalcResultEventArgs e)
{
EventHandler<CalcResultEventArgs> eh = CalcResult;
if (eh != null)
eh(this, e);
}
}
public class CalcResultEventArgs : EventArgs
{
public CalcResultEventArgs(string resultAsString)
{
ResultAsString = resultAsString;
}
public string ResultAsString
{
get;
private set;
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Excellent!! Thank you very much
Passing Data between Windows Forms[^] was very useful as well.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Just a quick point on this, setting a label on a form from a seperate class is probably not a particularly good idea. By doing that you've tightly coupled the class and form together which is bad for reuse. At the extreme you might as well put the calculation stuff in the form itself, as potentially the calc class can no longer operate without the form.
As Christian suggests, by exposing an event on your calculation class your form can get updated, but your class could be used elsewhere without that form.
Regards,
Rob Philpott.
|
|
|
|
|
Thanks for your comment Rob.
I was only trying to simplify my scenario as much as I can, the real application does nothing of this sort. I was only trying to explain in layman's terms.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Hello,
Can anyone help me to solve below problem at my pc.
Method not found:'Int32 Microsoft.VisualStudio.Shell.Interop.IVsRunningDocumentTable2.QueryCloseRunningDocument(System.String,Int32 ByRef)'.
Thanks.
Jem_Jumper.
|
|
|
|
|
1. Have you added Microsoft.VisualStudio.Shell.Interop.8.0.dll as reference?
2. Second parameter is out parameter.
जय हिंद
|
|
|
|