|
B is an A. C is an A. B and C can see protected and public members of A. There is no reference, B IS an A. C IS an A. You can cast it to an A if you want an interface that shows only what is visible to the base class.
If you want to iterate over this collection and know which A is a B and which A is a C, you can use the is keyword.
foreach(A a in aa)
{
if (a is B)
{
// it's a B
}
else
{
C c = a as C;
if (c != null)
{
/a is a C.
}
}
}
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
thanx Christian
its means to use the word "reference" is wrong in that senario
and my confusion is very much cleared now
|
|
|
|
|
Glad to help
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hello,
I am using two different instances of OpenFileDialog on two separate buttons to open file dialog.
In first dialog I am setting the path according to my requirement like this
openFileDialog1.Reset();
openFileDialog1.InitialDirectory = path;
But when i click other button to open file dialog, it opens at the location where first dialog was opened. Is it possible to store the different path location for each dialog?
regards
Gajesh
|
|
|
|
|
What are you asking? You are saying you are creating two different instances of OpenFileDialog--one for each button and when you change the initial directory for one, it is reflected in the second one? Reassure you are creating different instances because one instance should not have any affect on the other one. Post some code to clarify.
|
|
|
|
|
Thanks,
Please find the code here
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
openFileDialog1.Reset();
}
private void button2_Click(object sender, EventArgs e)
{
openFileDialog2.ShowDialog();
}
You will find that it always reset the path for different openFileDialog. It might be because of Reset() function.
Regards
Gajesh.
|
|
|
|
|
hello gajesh
use the code below to set different paths for openFileDialog
set for the openFileDialog the initial directories always...........
openFileDialog1.InitialDirectory= some path U Wish to open(store the different path location for each dialog);
thanks
Tony
|
|
|
|
|
Hi,
it all depends on FileDialog.RestoreDirectory:
- by default false, meaning your app's current directory will be set to your most recent selection (hence two dialogs will influence each other)
- when true, current directory is not affected (but if you want a dialog to open where
it got closed last time, then you have to program for that explicitly).
|
|
|
|
|
hey..........
plz respond
|
|
|
|
|
Thanks tony,
I found that the Reset() function is resetting path for all dialogs though they are different instances. I think i need to store the last path to the registry and read it back programmatically.
Regards
Gajesh
|
|
|
|
|
gajesh wrote: I found that the Reset() function is resetting path for all dialogs though they are different instances.
Of course not. It only resets the dialog that you call the method on. The other dialogs just use the current directory as initial directory. If you want a different initial directory you have to specify that for each instance.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for reply,
Have a look at the code
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Reset();
openFileDialog1.ShowDialog();
openFileDialog1.InitialDirectory = openFileDialog1.FileName;
}
private void button2_Click(object sender, EventArgs e)
{
openFileDialog2.ShowDialog();
openFileDialog2.InitialDirectory = openFileDialog2.FileName;
}
You can never go to the path which you accessed last time for the same dialog.
|
|
|
|
|
Of course you can, you only have to assign the correct value to the InitialDirectory property. A file name is not a path.
openFileDialog1.InitialDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello All!
I am trying to write all items inside my listview control to a text file and I have the following code, I am
using System.IO;
File.AppendAllText("C:\\Users\\Jase\\Desktop\\File.txt", listView1.Items.ToString());
So, when I click on a button it will write each item to file but it doesn't work and I haven't been able to find any help on google or msdn. Does anybody have any pointers/links/samples they'd be willing to share? Thanks for reading.
Regards,
j.t.
j.t.
|
|
|
|
|
A quick look at the ListView class members states that Items is a property which returns ListViewItemCollection so no need to look further. Since you are executing the ToString() method on the ListViewItemCollection it is basically returning a string that represents the current object which is probaly something like System.Something.Something. There is nothing weird about that. If you have a class say:
class Employee
{
public string ToString()
{
// Here is the implementation for the ToString() method. Some classes return the object name, some
// return something meaningful but it all depends on the implementation. Some can event decide
// to return "In your dreams this would work!" which is unlikely but as long it is a string, it is
// valid.
}
}
If you want all the objects then do this:
// First save the ListViewItemCollection returned in a ListViewItemCollection reference
ListViewItemCollection allItems = listView1.Items;
Then iterate over all the items using foreach or some other loop. The other option you have is to extend the ListViewItemCollection class and override the ToString() method to return all the items instead of the base class implementation.
Or you can do this:
foreach(ListViewItem currentItem in listView1.Items)
{
// Here write each item which is currentItem to file
}
|
|
|
|
|
It's not weird at all. You assume that ToString will iterate over the collection, and find some sort of meaningful string value for each item. It plain isn't going to do that. I would imagine that you're getting ListViewItemCollection written to your text file. You need to write the code to work out a format for each item and to iterate over the items.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Aaaaahhhh beautiful, now I understand Thank you so much CodingYoshi and Christian Graus! Your help is much appreciated.
j.t.
|
|
|
|
|
I have a table in SQL with a ID and Description. I want to display the description in the combobox but if you execute the insert statement it should take the ID of the description you selected.
How can I do this? I already have a combobox populated with the description but how do I get the ID?
Thanks !!
Illegal Operation
|
|
|
|
|
The combo box items have a display value and a data value. Something like that, there's a hidden field you can use to store your id.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Set the ComboBox's DisplayMember to what you want the user to see and the ValueMember to what you want to use. For example, combo.DisplayMember = "Description" and combo.ValueMember = "ID". Then get when user selects the item you want, simply get it by combo.SelectedValue and this will return "ID" in your case. Just remember "Description" and "ID" have to be encapsulated in Properties and not public fields and obviously private fields if using a class.
|
|
|
|
|
Is it possible to create a zedgraph and populate it from a dataset using the XMLReader (ds.ReadXml(myFilePath);)?
It seems that the XMLReader reads everything in as a string and the X axis of the intended graph are DateTime therefore it errors on the data type.
I though this might convert ... but it has not helped.
// Create a new DataSourcePointList to handle the database connection
DataSourcePointList dspl = new DataSourcePointList();
// Create a new Dataset
DataSet ds = new DataSet();
//Fill(ds);
string myFilePath = (Application.StartupPath + "\\trd.xml");
ds.ReadXml(myFilePath);
DataTable tbl = null;
tbl = new DataTable("getTrends");
tbl.Columns.Add("ID", typeof(string));
tbl.Columns.Add("UTCDateTime", typeof(DateTime));
tbl.Columns.Add("ActualValue", typeof(Double));
tbl.Columns.Add("Units", typeof(string));
tbl.Columns.Add("FullReference", typeof(string));
Any thoughts...
TIA
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Zedgraph is not a standard control. If it's a CP article, ask in the forum provided by the article.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
The questions were really about the XMLReader and Datasets not the zedgraph. That was just for the context....
thanks
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Oh, I see. XML is always strings. So, use DateTime.Parse if you're sure it will NEVER fail, or otherwise DateTime.TryParse. Same goes for your doubles, etc.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hello everyone !
I want to write a simple Winforms UI that uses a textbox to output logmessages. This is quite simple, and i have it up and running, but since i am new to C# and Winforms i was wondering what the recommended way/best practice for this problem is. Right now i just write the logmessages into a StringBuilder and update the Text-property of the TextView everytime a new message is added. Deleting older messages is not yet implemented but simple enough. I know that in MFC i could bind the text property to a string and it would be automatically updated both ways. How do i got about that in C#/Winforms ?
I know this is a very general question. I do not want a full answer here, just some hints and pointers where to look, since i am at a loss here (i looked up DataBinding on MSDN, but they only talk about DataBases).
Thanks, Brainley
|
|
|
|