My application is a form based application, having multiple textboxes that can be filled. Some textboxes however is optional and a checkbox is included to toggle if it should be included.
Now I would like to save the progress of the form so it can be opened later for further editing. I am saving this file as an .xml. Saving the textboxes I have no problem with, but what is the best way to save the state of the checkboxes to the .xml file, so it can be loaded later?
I can simply use - string s = Bool.ToString();.
It does work but when working with a lot of checkboxes it can become a long process. I have a class that handles the saving of the .xml file. Is there a way to add more then one checkbox to a list then parse the "true/false" value to the class as an array of Bool[]?
Checkbox-state is nothing else than an Boolean? -> Nullable bool. You can simple serialize it using an xmlserializer or write it manually to the file:
string s = checked.ToString();
and to parse it:
bool checked = Boolean.Parse(s)
Related
I'm trying to make a desktop application (WinForms) that reads an Excel template file and manipulates with it. So far i have managed to write data to specific column and save changes to the file from the application, but i have a problem.
My Excel template file has a drop-down populated with items from another sheet in one column.
Here is how my template looks like: My Excel template file
Sheet2 that populates the dropdown in Sheet1: Sheet2 - used to populate dropdown in Sheet1
I would like to be able to read those items in my application and select one of them,and also save changes to the file (with the selected item in the dropdown).
If that's not possible, i would like to know if there's any possibility to select an item in a specific index from the application (for example second or third item in the dropdown list and save changes to the file)
I have searched a lot to resolve this issue, but i haven't got any correct answer yet.
I have a productlabel (.lbl file crated with NiceLabel).
Using Wingforms (c#) I want to open this label file and get the fields so I can assign data (from my database) to them and then save the label.
So in the end, I have a label with values that I can print.
Is a way t do this?
Edit: If possible, it would be awesome to also show the finished label in the form, to see if all values are in correct place.
I have an ASP.net 4.5 text box with 5 rows. When I save the below data to my table it does not take in consideration that there are line breaks.
Example:
Hello my name is Mike!
How are you?
Please can you help?
When saving this data to my table it of course save it like this below and it will be displayed like this again if I populate my website with this value.
Hello my name is Mike!How are you?Please can you help?
But I want it to be displayed with the line breaks as the way it was written in the first place.
The thing is, I do not want to make use of a custom form item because then the user will be able to copy and paste all html from another website in and I do not want that.
Any idea how this can be done without using a plugin such as below where the user will be able to copy and paste data into?
To populate your text box from the database try;
TextBox1.Text = someText.Replace("\r\n", Environment.NewLine)
For Label
Label1.Text = someText.Replace("\r\n", <br />)
Alternatively you could save the data to your database with the
someText = TextBox1.Text.Replace("\r\n", "<br />")
Although this approach may not be appropriate if the database is also used elsewhere.
I am currently serializing a List<SomeObject> to an XML file, which works fine...
In the SomeObject properties, one of them is a string that contains multiple items delimited by the Environment.NewLine character.
When i open the XML file using Excel, some of the cells containing that property, with a few items in them, show up fine (WrapText is set) and yet some others with more items just show up as a string of # signs.
Is there a way to properly show the property's contents with the new lines in there so that Excel displays them correctly, while retaining the original XML? I mean, is this a Serialization issue, or a display setting in Excel i've missed?
The only way i was able to get the text to display properly, was to highlight the entire column in excel, and set the format to Custom -> 0 ... otherwise, in its original format of Text, i only get # signs...
Did you check to see if the XML document was formatted correctly? Because infinite #################### in a cell usually means something is either formatted incorrectly or Excel doesn't understand its type. For example, Excel can't do negative time so subtracting Earlier Date from Later Date = infinite #######. If you hover your mouse over the cell, it may tell you what the issue is.
I load an xml file into an Xelement. I then look for an an element named R via:
XElement elem = xmlTemplate.Descendants().Where(x => x.Name.LocalName == "R").FirstOrDefault();
I then search for the attributes EF and EX via:
elem.Attribute("EF").SetValue(txtEffective.Text);
elem.Attribute("EX").SetValue(txtExpire.Text);
but when I call xTemplate.Save(...), it does not save the udpated attributes. I have also tried:
elem.Attribute("EF").Value = txtEffective.Text;
elem.Attribute("EX").Value = txtExpire.Text;
I found out the problem, but not sure how to avoid it. When I load the XML, I am loading the two attributes in two text boxes on the form. When I change the values in the text box to update the attributes, it is updating the xml with the original values in the text box and not new ones. I wonder if this has to do with the fact that the text boxes are loaded on page load and when I click the button, it actually loads the xml again and overwrites my new values with the original values. After I did not load the values in the text box, the save worked fine.