|
Is it possible to specify this as an attribute parameter for PInvoke? This should be compile time binding if possible.
|
|
|
|
|
Hi All
I knew the basic use of it(to use it with base methods so that use can override them in derived classes.)
But what is the use of overriding a method in derive class. We also achieve the same by creating another function too in the derive class.
Please let me know the real advantages of using virtual in base class.
Regards
Varun
|
|
|
|
|
Simple: if you specify virtual when your base class creates a method, then it can (but doesn't have to be) overridden in the derived class.
Lets take an example: a Fruit class.
If you create a virtual Peel method which uses a knife to cut away the peel, you can override it in your derived Apple class to use an apple peeler - because it does a better job. And in your Orange class to just use your fingers.
But in all cases, you just call the Peel method from other code and it doesn't need to worry about which actual method is used. Just as if I threw you a paper bag containing a piece of fruit and told you to "peel that". You would open the bag, and decide on the best method to use to do it - knife, peeler or fingers - as a result of which fruit you found: A Mango would need a knife, an Apple a peeler, and an Orange your fingers.
When you use virtual in your base class, the system will use the most-derived version:
public class Fruit
{
public virtual void Peel(){Console.WriteLine("Knife");}
}
public class Orange : Fruit
{
public override void Peel()
{
Console.WriteLine("Fingers");
}
}
public class Apple : Fruit
{
public override void Peel()
{
Console.WriteLine("Peeler");
}
}
public class Mango : Fruit
{
}
And so
Orange o = new Orange();
Apple a = new Apple();
Mango m = new Mango();
Fruit f = new Fruit();
o.Peel();
a.Peel();
m.Peel();
f.Peel();
f = o;
f.Peel(); Will give you:
Fingers
Peeler
Knife
Knife
Fingers Without you having to look at what type of Fruit it is and calling the appropriate Peel method yourself.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Thanks
Main answer to my question lies in your last line.
"Without you having to look at what type of Fruit it is and calling the appropriate Peel method yourself."
Please let me know if there are any other advantages too.
|
|
|
|
|
|
Hi everyone,
I am writting an program in C#, that use SQL Server database.
My program include a blank database (sample database) that allow users can create a new database.
For example:
- User 1 use my program to create a new database (DB1) on his computer, then he import/enter some data into DB1
- User 2 use my program to create a new database (DB2) on his computer, then he import/enter some data into DB2
Now, I have both two database (DB1, DB2). Do you know how to merge/combine two databases to have unique database that contain all users' data ?
Can you help me ?
Thank you very much,
Tai
|
|
|
|
|
|
i´m trying to bind a list to a datagridview. i do that:
public void seedatagrid(List<myClass> liste2)
{
dgv_TraceItems.DataSource =liste2;
}
and the datagridview has the data, but it doesn´t show anything.
could you help me?? how can i resolve the problem?? thank you
the class
public enum TYPE
{
normal= 1,
especial= 3,
low= 6,
high= 7,
}
public class myClass : INotifyPropertyChanged
{
private byte number;
private TYPE type;
private string file;
private bool isselected;
public event PropertyChangedEventHandler PropertyChanged;
public byte Number
{
get
{
return this.number;
}
set
{
this.number= value;
this.OnPropertyChanged("Number");
}
}
public TYPE Type
{
get
{
return this.type;
}
set
{
this.type = value;
this.OnPropertyChanged("Type");
}
}
public string File
{
get
{
return this.file;
}
set
{
this.file = value;
this.OnPropertyChanged("File");
}
}
public bool IsSelected
{
get
{
return this.isselected;
}
set
{
this.isselected = value;
this.OnPropertyChanged("IsSelected");
}
}
public myClass(UInt32 Data, string Text)
{
this.number = (byte)((Data & 0x0000FF00) >> 8);
this.type = (TYPE)((Data & 0x00FF0000) >> 16);
this.file = Text;
}
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
i have tried to make a datatable with the list and the datagridview doesn´t show anything. i don´t know what happends , but i have a problem with the datagridview
|
|
|
|
|
Some things to look at:
* is it Asp.Net? I remember back in the days you also had to call the databind method. Not sure if it changed in newer versions.
* Is the datagridview "aligned" with the source you put into it? IOW the values of the class are not appended at the end of the grid (column wise) or the datagridview doesn't know what to do with the properties you're putting in? In short, you're pumping in a block of data, but you need to tell the datagridview what parts of the data are for which column.
Hope this helps.
|
|
|
|
|
ok, i understand you say,but i don´t know how to make it, hehe
how can i tell the datagridview what parts of the data are for which column?
with a list or with a datatable there is a problem with the datagridview.
because if a make a datatable with the list (all as string) and after i send the datatable to the datagridview, and the datadrigview doesn´t show anything. what problem is??
thank you
|
|
|
|
|
If you haven't defined any columns in the designer it should do this for you, no problems. If you did define columns I guess you also need to define the "link" to the data you're attaching. You can do this in the designer and in code I guess (it's been a while since I did this).
I would try to find some samples on MSDN.
|
|
|
|
|
i have definde any columns, but i tried too columns definded, but it´s the same.
any sample would be helper
thank you
|
|
|
|
|
I would try to find some samples on MSDN.
|
|
|
|
|
i have definde any columns, but i tried too columns defined, but it´s the same.
any sample would be helper
thank you
|
|
|
|
|
Start by using the debugger: put a breakpoint on the line:
dgv_TraceItems.DataSource =liste2;
and check that the list contains class instances.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
hi,
i have a breakpoint there and it contains all, and the datagridview too.
dgv_TraceItems.DataSource Count=9
but it shows nothing.
|
|
|
|
|
Where is seedatagrid being called from?
It's perfectly valid to just set the DataGridView.DataSource to a list of class instances, and the system should (and does) pick out the public properties and display them in columns. I do it all the time, especially for testing, so I know it works without any supporting code.
Try this:
dgv_TraceItems.DataSource = new List<string> { "hello", "goodbye" }; You should get two rows of one column, with values 5 and 7.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
i tried
dgv_TraceItems.DataSource = new List<string> { "hello", "goodbye" };
datasource contains "hello", "goodbye", but it shows also nothing, do i have a problem with the configuration of my datagridview??
thank you
|
|
|
|
|
OK - we've eliminated data as a possible cause, so that leaves us two things: first it's being called in the wrong place - so where is it being called from? What event or top level method?
Do you get any rows at all? Any column headers?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
public void seedatagrid(List<myClass> liste2)
{
dgv_TraceItems.DataSource =liste2;
}
this funtcion is called in Form1.cs and goes to table layout panel where is the datagridview.
i get any rows and any column headers.
thank you for helping
|
|
|
|
|
Yes - but it will be called from a method - it isn't an event handler so it has to be called from somewhere - like the form constructor, or a button click handler, or similar.
"i get any rows and any column headers." does this mean you do, or you don't? If you do, how many of each?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
void pChannelKonfig_EnabledChanged(object sender, EventArgs e)
{
list_to_dgv.seedatagrid(testInfo.Information);
}
i call it here. testinfo is the name of a class and Information is th List
|
|
|
|
|
OK - so is list_to_dgv a form, or what? Because if it is, you need to make sure it is the right instance of the form as is currently displaying, because the seedatagrid code will set the DGV on the specific class instance you call it on. So if you aren't using the right list_to_dgv, then the DGV will get the data, but the DGV itself isn't displaying, because the form it is part of isn't displaying - which would explain your problem!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
this is testInfo class:
public class TestInfoClass : INotifyPropertyChanged
{
private string fileName;
private List<BLF_InfoClass> information;
public event PropertyChangedEventHandler PropertyChanged;
public string FileName
{
get
{
return this.fileName;
}
set
{
this.fileName = value;
this.OnPropertyChanged("BlfFileName");
}
}
public List<InfoClass> Information
{
get
{
return this.information;
}
set
{
this.information = value;
this.OnPropertyChanged("Information");
}
}
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
and this is list_to_dgv (UC_Configuration is a Form)
public partial class UC_ChannelConfiguration : UserControl
{
public UC_ChannelConfiguration()
{
InitializeComponent();
}
public void seedatagrid(List<BLF_InfoClass> liste2)
{
dgv_TraceItems.DataSource = liste2;
}
}
|
|
|
|
|
So...
list_to_dgv is a UC_ChannelConfiguration instance,
and it's embedded in a UC_Configuration form instance.
Yes?
So that means that pChannelKonfig_EnabledChanged is an event handler within the UC_Configuration form, and that you have just the one single instance of the form ever created, and one UC_ChannelConfiguration
instance inserted in the designer? Or do you manually create those, since you were earlier talking about a TableLayoutPanel?
Basically, all the code you have shown should work: so the chances are it is working - but it's probably affecting an instance of the DGV that you can't see, and I can't see enough of your code to work out which one it is affecting, so I'm trying to ensure that we are talking about exactly the same situation rather than me assuming stuff you already know and getting it wrong.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|