|
In a windows form I have a textbox and a button. Initially the text box contains "Enter ID" as the default text. I enter some ID and click the button which saves the ID to an XML. After that, the text in the textbox should revert back to "Enter ID" as before.
Right now my code is a below...
// Windows Form Designer generated code
// First time I intialize the dafault text
this.txtbox1.Text = "Enter ID";
// Button_click
private void button1_Click(object sender, System.EventArgs e)
{
//Write To File and reset all textboxes on the form for default text
SaveToXML();
ResetAllTextBoxes();
}
// Reset all text boxes on the window
private void ResetAllTextBoxes()
{
this.textbox1.Text = "Enter ID";
....
....
this.textbox10.Text = "There has to be some another way"
}
I'm not satisfied with this implementation because if I have 10 textboxes I need to have 20 lines of code doing the same. 10 lines in the Windows Form Designer generated code and 10 in ResetAllTextBoxes() method.
I tried the textbox1.ResetText() method but instead of reseting it to default text such as "Enter ID" it resets to blank.
Is there a better solution.
Thanks
----------
Venus Patel
http://patelsinc.blogspot.com/
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
-- modified at 17:25 Tuesday 10th January, 2006
|
|
|
|
|
No. You have to write the code to change the values, and the auto generated code will stay the same. Personally, I would not set the values in the forms designer, but just in a method, and call the method after InitializeComponents is called, just to put it all in one place.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You could make your own custom textbox that inherits the built in textbox, and that has a DefaultText property. To easily reset all textboxes, keep a static Arraylist in the class, where each textbox adds a reference to itself when it is created. Then add a static method to the class that loops through the Arraylist and resets the text of each textbox.
---
b { font-weight: normal; }
|
|
|
|
|
I've added a Shockwave object to my WinForm and I'd like to have it respond to a mouse click.
Is there anyway to do this?
I've seen stuff that says you can catch the FSCommand event - the problem is I'm using just plain ordinary SWFs and I can't guarantee that they will have an FSCommand.
TIA - Jeff
|
|
|
|
|
|
Hi, I am writing a small program that opens a very large (almost 4GB) XML file, then looks through the data for various text matches etc. (I don't need to display or write to the XML file).
The problem I have is using the following code to open the XML file;
StreamReader sr = new StreamReader(Filename);
XmlTextReader xr = new XmlTextReader(sr);
XmlDocument XMLdoc = new XmlDocument();
XMLdoc.Load(xr);
This loads the entire file, which causes an OutOfMemoryException error when it reaches the 2GB limit. It works ok for small XML files that I have been testing on, but I dont know how to deal with this massive file.
I assume I am meant to open the file in chunks or something, but I haven't been able to find any info on how acheive this (other than upgrading to 64bit, but that isnt really practical).
Can anybody point me in the right direction?
thanks!
|
|
|
|
|
You could parse the nodes yourself if the file has a basically simple structure, e.g. something similar to:
<root><br />
<node ... >...</node><br />
<node ... >...</node><br />
<node ... >...</node><br />
<node ... >...</node><br />
<node ... >...</node><br />
... lots'a nodes<br />
<node ... >...</node><br />
</root>
By reading the file in small parts, you could extract the complete nodes you find in that part of the file, put them in a separate xml document in a string and load it into a XmlDocument object.
Pseudo code:
buffer = ""<br />
loop {<br />
buffer += stream.Read(lotsabytes)<br />
find first "<node>" in buffer<br />
find last "</node>" in buffer<br />
nodes = get what's between<br />
buffer = what's after<br />
xmldoc.LoadXml("<root>" + nodes+ "</root>")<br />
... do whatever you want with the nodes<br />
}
---
b { font-weight: normal; }<
|
|
|
|
|
I see what you're getting at, thanks!
|
|
|
|
|
I believe the XMLDataReader provides a solution that reads the file as it parses it. If not, there must be some control that works as SAX instead of DOM, and doesn't hold the whole file in memory.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yes, take the SAX approach -- open it as a Stream and use XmlTextReader. Not only will it help in not running out of memory, but it would be faster than the DOM approach even if you did have enough memory to load the whole thing.
Stream stream = new FileStream(fileName, FileMode.Open);
XmlTextReader reader = new XmlTextReader(stream);
reader.WhitespaceHandling = WhitespaceHandling.None;
while (reader.Read())
{
...
}
This is also a lot better idea than parsing the file with regular expressions, or worse, junk like text.IndexOf(blah) , especially when you consider the fact that there is no guaranteed that a whole xml file isn't a single line of text (then you are back to loading the whole thing into memory, probably).
Matt Gerrans
|
|
|
|
|
Thanks guys, I should mange from here!.
|
|
|
|
|
> Thanks guys, I should mange from here!
Hmm... I think soap and water will help with that. If not you should probably see a doctor.
Matt Gerrans
|
|
|
|
|
I have a custom control that I'm writing, and one of its properties is a collection. Everything works fine, except that the collection property shows a bolded (Conditions) value for it. I'd like to remove the bolding, and I'm ditzing on how to do this. Any ideas?
Thanks in advance.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
|
See, that's what I thought, too. I couldn't make either combinatin work, though it's completely feasible that I'm just missing something. I'll post the answer when/if I find it. Thanks, though.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
Summary Question: How can I do pointer fix uping using XML Serialization?
I'm getting tripped up over one idea when performming XML serialization.
Lets say I have a simple class structure where Students have Teachers.
<br />
class Teacher<br />
{<br />
public string name;<br />
}<br />
<br />
class Student<br />
{<br />
public Teacher mTeacher;<br />
}<br />
<br />
main<br />
{<br />
Teacher teacher = new Teacher();<br />
teacher.name = "Mr Smith";<br />
<br />
Student [] students = new Student[2];<br />
<br />
students[0] = new Student();<br />
students[1] = new Student();<br />
<br />
students[0].mTeacher = teacher;<br />
students[1].mTeacher = teacher;<br />
<br />
...<br />
<br />
SERIALIZE students[]<br />
...<br />
DESERIALIZE students[]<br />
<br />
}<br />
What I'm finding is that when I serialize/deserialize, I'll find that each student has their own unique teacher "Mr Smith" rather than both students sharing the same teacher.
When I do this kind of serialization using a BinaryFormatter I find that the teacher is not created twice and that the serializer realizes that this object has already been serialized and essentially stores a pointer and when the object is serialized, that pointer is fixed up.
Summary Question: How can I do pointer fix uping using XML Serialization?
|
|
|
|
|
IIRC, the XML Serializer doesn't support object pointers. The values they point to are searialized. I THINK! I can't confirm this or find the concrete docs that explain this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I cannot imagine it would matter whether you use BinarySerialization or XML serialization; fact is, the serializer has no idea about whose point to whom. You're going to have to manually set the teacher reference to share the same object if you it to act that way.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
|
Wow. I stand corrected. Thanks for the info.
|
|
|
|
|
There is alot of potential problems though.
If your app relies on instances serialized in its runtime then you have to do fixups when deserializtion (that is if you can 'reset' the app state). The big problem now is how to correctly identify the type 'value' and hence map it, as the deserialized object and the currentobject will be a memberwiseclone of each other, but still 2 objects. If you have a valuetype, then you wont have this case. So the only other way is mutable and unmutable reference classes. Typically you would just override equals and hashcode and this would work fine on a hashtable. But as soon as you have a mutable object, where the hashcode is dynamic it gets tricky.
A solution to this problem is to have a fixup hashtable mapping T to T. Then at deserialization you do fixups[myobj] = myobj , and allways use fixups[myobj] to retrieve the actual object. Its all a bit tricky, but it works well
xacc.ide-0.1.1.10 - now with AutoComplete(kinda)
|
|
|
|
|
What's the best way to display a web page on a windows form? I'm using VS.NET 2003 and C#
-- modified at 15:20 Tuesday 10th January, 2006
|
|
|
|
|
Add a WebBrowser control from the toolbox, then you can navigate to a webpage with code such as;
webBrowser1.Navigate("http://www.codeproject.com");
|
|
|
|
|
how can i get my computer in a Standby mode using c#?
simply i want to get my pc sleep and wake it up after a period of time
-- modified at 7:59 Wednesday 11th January, 2006
|
|
|
|
|
shabonaa wrote: how can i get my computer in a safe mode using c#?
You can't. Safe mode is only available on boot.
shabonaa wrote: simply i want to get my pc sleep and wake it up after a period of time
Far from simple. You're looking at using the Windows Power Management functions to set a wake timer and put the system in StandBy. See this[^] for more information. I wasn't able to find any examples of anyone using this. It's just functionality that's rarely ever used from inside an application.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|