This question already has answers here:
WPF ObservableCollection Edit Mode
(4 answers)
Closed 7 years ago.
I have an application that collects data in the background, displays data with one window, and has another form that can be used to update data objects. Data is stored in an observable collection that can be accessed application wide.
I would like to know the best way to edit the data with one form (the form must have an option to save the data, or cancel editing), and have the other window still display current data.
My idea right now is to have the form bind to a copy of the data object being edited, and then only replace the object in the ObservableCollection when the user confirms the changes. But I would like to know if there is a better way to go about this?
I would have the object expose both inprogess and final values. Bind to the final and have a method in the object to copy inprogress to final.
Related
This question already has answers here:
NumericUpDown differentiate up and down
(2 answers)
Closed 9 months ago.
Is there a way to detect with the Numeric Up-down control to see if the Up or Down button is pressed without coding?
I know I could keep track of the current value and write some code in the method ValueChanged. I was just thinking maybe there is an easier/shorter way to do this
If you want to track specifically the buttons being used and not the value being changed directly you can create your own UserControl that inherits from NumericUpDown and override the UpButton() and DownButton() methods. Otherwise if you want to track all value changes, using the ValueChanged event is the best way to cover all ways of changing the value, including programatically.
This question already has answers here:
Manual editing of *.designer.cs file
(5 answers)
How to modify code in designer.cs
(1 answer)
The *Design.cs file will reset automatically and delete the manually writed codes?
(1 answer)
Closed 2 years ago.
In C#, I have some comboboxes functioning as dropdown lists. The first value in the collection is the one I want to show as default to the user. Therefore, I added a line to the designer file, so that upon load, first value, aka index 0, is shown.
combobox1.SelectedIndex = 0;
It works! I do the same for every other combobox in my app, however, this keeps disappearing from the designer file. How can I fix this?
Thanks in advance.
As mentioned in comments:
The designer file is not for you to edit - there is a comment in the file to that effect. The Designer is constantly rewriting the designer file to reflect changes it needs to make. Move your code to someplace such as the form load event
As the programming noob I am, I overlooked adding an OnLoad method with the selectedindex for each combobox. That solved my problem!
This question already has answers here:
How can I export data to an Excel file
(7 answers)
Closed 7 years ago.
I am new to C#. I am currently learning how to write a window form application. I want to export some of my data from my form to an Excel file.
I am wondering what is the best way to approach this problem?
I have looked through many tutorial site and YouTube video and most of them suggest to use a data grid view. One thing I notice is that datagridview work well with simple GUI layout like the textbox.
However, what if I have some other complicated components such as a checkbox and a comboBox in my form?
Data grid view seems not the best option to do it. Are there any other better solutions to this case?
The approach depends on the desired result. As far as I know, Excel is able to import from a delimiter-separated text file. Depending on the context, it might be a valid approach to programmatically write to a text file which is then read by Excel.
This question already has answers here:
Loading user controls dynamically
(3 answers)
Closed 7 years ago.
I need a way to dynamically add user controls to a page, then pass data to those user controls. Then, on a button click, grab all the data from those controls. There will be textboxes, and radio buttons, and dropdownlists and so on in the controls. Can anyone recommend a convenient or efficient way of doing this? Preferably in a way that uses methods built into ASP.net and C#.
Maybe try using a dialog that you can reuse to display or post values
IF your trying to add/view data
This question already has answers here:
Can I display links in a ListView's detail mode?
(5 answers)
Closed 9 years ago.
In my windows application, I have a listview, which contains two columns. One of the subitem in a row contains the data as below.
"Failed testcase path=C:\temp\test.jpg"
I need to provide hyperlink to only C:\temp\test.jpg. If I click on the same, it should open the corresponding image.
I tried by changing the property HotTracking to true.
listView1.HotTracking = true;
But it shows hyperlinks to all the rows in listview.
Is there a way to achieve this?
Use ObjectListView -- an open source wrapper around a standard ListView. It supports links directly:
This documents the simple process and how you can customize it.