|
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
|
|
|
|
|
Hi,
I recommend using a ListBox instead of a TextBox when ever the content is line oriented.
A TextBox is meant to hold one piece of text, and it effectively stores a single string,
which would be the (expensive) concatenation of all your individual log messages.
A ListBox on the other hand is aimed at displaying and manipulating lists, that could be lists of single-line strings. Nothing gets concatenated, all items in the list are kept separately, and they can be added, removed, modified, etc. Much easier, and much faster, especially when the total size of the contents increases. I have been using ListBoxes holding millions of messages; I can't imagine getting satisfactory results from a TextBox for such work loads. A StringBuilder would not solve the performance problem at all.
|
|
|
|
|
Agree with Luc, use a ListView, change the view to detail, add a single column, and make de column width be the same as the listView (you may handle the onResize event of the listview to make it work ok)
You can use a rich text box too but will be more complicated to delete all data
Saludos!!
____Juan
|
|
|
|
|
To put things straight, I mentioned ListBox, not ListView (maybe ListView can be
as performant as ListBox, but I am sure ListBox is the easiest one to use).
And RichTextBox is in no way easier or cheaper to use for line-oriented output as
a standard TextBox is.
BTW if I need minor formatting (say optional styles such as bold, or a few colors,
then I turn the ListBox into an OwnerDrawn one, and either store strings with a
special first character, or store objects of a very simple class holding text plus
some style flags.
|
|
|
|
|
|
I need to read some file from over 200 different pcs and then insert them into the database. The application should not hang if it can not read from one pc due to whatever reason so I am thinking of doing the read asynchronously and when done will be directed to a routine which will insert them into db. I need to do some work with the data first before inserting into db so I am taking the csv file contents and putting them into a DataTable object. Is this Ok or are there any precautions I should take?
What should I watch out for?
What can go wrong?
Should I use Async or it is not needed?
Thanks,
|
|
|
|
|
I am amazed to find that nothing exists (that I can find from a internet search and here at CP) to suspend a windows form from updating itself.
I've tried suspendlayout and resumelayout methods of the form with no luck.
I see calling the win32 api is one way but wow, this could easily be done in VBA with "ScreenUpdating=false" then set to true again when you wanted to hide screen happenings from the user.
My needs arise from programmatically setting some control's (comboboxes, textbox) values that I don't wish the user to see necessarily.
Any ideas?
|
|
|
|
|
Why would you set values to controls if you don't want the user to see them ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
The user will use the controls to input information of course. But, I want the user to be able to do a "quick entry" of sorts, by a less onerous method via some other controls (radio buttons) that, based on these simple choices, cause code to programmatically set the values of these other more numerous controls (with their events firing etc that I want).
What my goal is by this design is to 1)make common entries faster for the user to enter and 2)ensure the logic (there's quite a bit of interactions of the controls) of these controls to be the only path of creating the data that the user will be storing via the app. ..so it's a single pathway of logic/code/bug opportunity & fix, in determining the many data elements that the user needs to indicate to the app for what they need to store.
Anyway, since my original post I found that I could just set the container of the controls, in this case a tabpage of a tab control, to not visible for the time in question, then set it back to visible afterwards. That seems to work well enough. . .I was just surprised to not have another way of doing what had been available in VBA.
I guess if one had a bunch of controls on a form and wanted the user to see them but also have done what I am aiming at then it would be a little more difficult without the way that is easy in VBA (screenupdating=false).
|
|
|
|
|
OK. Well, what you're doing seems the most sensible way of achieving that to me. I'd just think if you have a quick entry method, there's no reason for the client not to see the result. But, you understand your business rules better than I do, I guess.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
If i have employee class properties such as ID and Name then i can get their data respectively through the attributes. Is it possible to get the entire employee object rather than getting the individual property data. I mean how can i delcare an attribute that can hold the class reference where it is delcared
public class Employee
{
[TypeConverter(typeof(EmployeeID))]
public string ID
{
get{return id;}
set{id=value;}
}
[TypeConverter(typeof(NAME))]
public string Name
{
get{return name;}
set{name=value;}
}
}
|
|
|
|
|
updatecom.CommandText="update test2 set name='" + textBox1.Text + "' job= '" + textBox2.Text +"' title='" + textBox3.Text + "'where id=" + textBox4.Text + "";
Ahmed hassan
|
|
|
|