|
xtr = new XmlTextReader(filename);
while (xtr.Read())
{
if (xtr.NodeType == XmlNodeType.Element)
{
if (xtr.LocalName.Equals("Days"))
{
this.cbodays.Items.Add(xtr.Value);
}
}
}
the <Days>21,"21"</Days> was just test data, I was trying to use the <Days>20</Days> but that gave me just the blank drop down box, so i was wondering if it just took my numbers and made them the index of the combobox so I put a few different data formats in the XML file to see if that made any difference
I have used a switch statement to check for XmlNodeType.Element and gives same results, if I change .equals("days") to an name that is not in the file I just get one blank drop down, currently it looks like it see that there are the right number of records but no data in the drop down
Rob
|
|
|
|
|
Planker wrote: this.cbodays.Items.Add(xtr.Value);
Substitute xtr.Value with xtr.ReadElementString() in the above line.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thank you, that worked. is there a reason that xtr.Value works for text boxes and you need readelementstring for combobox?
|
|
|
|
|
No, there isn't. I think that xtr.Value doesn't work for text boxes too. But I must test it...tomorrow...maybe!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
thank you for your help, wondering if you could answer a question about writing back to the xml file.
I think you are right, I looked at my other code again and i was using ReadString
I am getting an error at run time on this line of code
newDayIndex.InnerXml = index.ToString();
here is how i'm doing all the xml code
XmlTextReader reader = new XmlTextReader(C_strFileName);
XmlDocument doc = new XmlDocument();
doc.Load(reader);
reader.Close();
XmlNode oldIndex;
XmlElement root = doc.DocumentElement;
oldIndex = root.SelectSingleNode("/config/Days_Index");
XmlElement newDayIndex = doc.CreateElement("Days_Index");
newDayIndex.InnerXml = index.ToString();
root.ReplaceChild(newDayIndex, oldIndex);
doc.Save(C_strFileName);
|
|
|
|
|
1) You should first correct these:
<days>21, "21"
<days>20, "20"
2) Then check if it you are really reading the values from the XML file correctly.
3) Use Convert.ChangeType(...) to convert the values you read to a specific type if you want.
4) Update ComboBox.DataSource Property with the list of values you read ( check out MSDN Library for ComboBox.DataSource Property on how to add specific, custom data sources to ComboBox )
Hope this helps...
|
|
|
|
|
Thanks for the info, i got the loading of the combobox working, i am not trying to figure out how to save the changes back to the xml file if the user changes the value.
|
|
|
|
|
I know that you are not trying to save back the user modified values to the XML file. What I suggest using Convert is to give you the ability to store the datatype of the object(what ever you create) as a string value and then convert it to what you want. You may also write a custom type converter or implement iSerializable interface or add XmlAttributes to your fields for which you want to serialize.
|
|
|
|
|
yes I am trying to save back the user modified values. I'm updating a config file so when the program is shutdown the changed value is read the next time the program is run.
|
|
|
|
|
Do you know what you want?
This is your post:
Thanks for the info, i got the loading of the combobox working, i am not trying to figure out how to save the changes back to the xml file if the user changes the value.
And now you are saying:
yes I am trying to save back the user modified values. I'm updating a config file so when the program is shutdown the changed value is read the next time the program is run.
Are you OK?
|
|
|
|
|
I've been trying to a simple Comm program to work using the
ReadExisting method of the .Net 2.0 SerialPort class.
The data is being transmitted to me from a PIC micro dev board.
The data received event fires when ReceivedBytesThreshold is
reached as it should, but I only get back one character when there are
4 in the buffer. I verified this by retrieving the BytesToRead
property and it is set to 4.
If I add additional ReadExisting method calls afterwards I will get
one and only one char back for each read.
I also tried the Read method but same result as ReadExisting.
Lastly I ran Hyperterm and another terminal program
and they both receive the entire 4 chars with no problems.
The databits, baudrate, and handshaking are all set the same
for my code as well as the terminal programs. I have also
tried setting the DtrEnable and RtsEnable to true but with
no success.
sorry for the long post but i tried to be as brief as possible
Any help will be greatly appreciated.
|
|
|
|
|
Hi, since ReadExisting reads bytes but returns a string, I would guess you have a problem with
the encoding. Why dont you use Read(byte[],...) ?
|
|
|
|
|
Its possible but then why do the successive ReadExisting invocations
return the characters that were sent? I will give it a try.
|
|
|
|
|
|
Hi,
SerialPort.Read documentation contains following note:
"Because the SerialPort class buffers data, and the stream contained in the BaseStream property does not, the two might conflict about how many bytes are available to read. The BytesToRead property can indicate that there are bytes to read, but these bytes might not be accessible to the stream contained in the BaseStream property because they have been buffered to the SerialPort class."
If you want specific help, show all code involved + port settings + actual bytes received.
|
|
|
|
|
I understand the documentation but that does not explain why I never got
the data. It would explain it if I only checked one time.
I ran the release version of .exe and I receive data without any changes to
existing code. However the reception rate is very slow compared to
something like hyperterm. I ran another Serial Terminal program
that I downloaded from an article on CodeProject and it does the same
thing. I think I may need to play with the read timeouts. So far
Im not very impressed with .Net's support for serial ports. [rant] I have
probably done something similiar to this at least 10 times before
on other platforms or development environments including Visual C++
and never had so much trouble. [end of rant]
|
|
|
|
|
Dear Friends,
What i want is that whenever i add new form in my application using Visual studio, it should appear in some different color and contains some different icon than what VS adds in default. Plz tell me how
Imtiaz
|
|
|
|
|
hi
i'm not sure that i got your question but may you can use visual studio templates
then you can add your custom form in 'Add' dialog box instead traditional windows form
I Wish the Life Had CTRL-Z
|
|
|
|
|
How can I copy a file and preserve the creation date?
|
|
|
|
|
i know a trick with MS-Dos command prompt but i think it will not be usefull for you
however if you didn't find your answer try System.IO.Directory.SetCreationTime
as your last solution
I Wish the Life Had CTRL-Z
|
|
|
|
|
Hi,
Explorer when copying a file sets creation time current,
but preserves last modified time (which seems logical).
And I assume File.Copy does the same.
AFAIK there is no function that does it differently.
You could make a method that copies a file and restores some
of the file properties, e.g. by using File.Get/SetCreationTime.
Regards,
|
|
|
|
|
Yeah! I am now using Western Digital drive mirroring but it is not convienent. Did a thirty day agricultral experiment that required date and time of each picture to be recorded. Did not realize that this data would be lost when the images were transfered from the chip to the hard drive. Lost thirty days work.
Guess Ile have to write a piece of software for this.
|
|
|
|
|
Two ideas:
If the file is created and written only once (i.e. not modified afterwards) on a Windows
system, then the "last written" or "modification" date should not change when the file
gets copied by either Win Explorer or File.Copy
If your pictures are JPEG files generated by a camera, it is very likely they contain a lot
of "properties" including the date & time of exposure (assuming the camera's real-time clock
has been initialized correctly...).
|
|
|
|
|
Luc
Thanks the modified date is correct for all the pics. So I will be able to salvage my work. Some how modified does not seem to be good terminology for when a picture is taken but thats MS for ya. I still am going to write a copy utility for my own use. The code below seems to work. Any Suggestions.
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
string infile="";<br />
string outfile = "C:\\test.jpg";<br />
OpenFileDialog dlg = new OpenFileDialog();<br />
if (dlg.ShowDialog() == DialogResult.OK)<br />
{<br />
infile = dlg.FileName;<br />
File.Copy(infile, outfile, true);<br />
File.SetCreationTime(outfile,File.GetCreationTime(infile));<br />
} <br />
}<br />
-- modified at 17:54 Saturday 5th May, 2007
|
|
|
|
|
Hi,
1. file times
creation time is when the file got created
modification time is when the file contents last have been modified
and yes that can be before creation time (when file gets copied, as you have experienced).
2. code comments
I would put infile declaration and all actions inside the OK? test
3. JPEG
as I said before, JPEG files typically contain a lot of properties, which may be the safest way
to retrieve exposure information. If you want to make sure for your files, just mail me one.
Regards
|
|
|
|