I know how to add buttons in runtime but in every new start application they got deleted. What is the best practice to save them every time they got created?
Asked
Active
Viewed 72 times
0
-
You need [persistence](https://learn.microsoft.com/dotnet/csharp/programming-guide/concepts/serialization/walkthrough-persisting-an-object-in-visual-studio). Do you want to use .NET Application Settings system, a custom BIN/JSON/XML/TXT file, or a real database like SQLite or SQL Server ? – Jun 01 '21 at 01:15
-
Does this answer your question? [C# .NET - method to store some very small scale persistent information?](https://stackoverflow.com/questions/10323755/c-sharp-net-method-to-store-some-very-small-scale-persistent-information) – Jun 01 '21 at 01:20
-
With using Application settings would be perfect if it is possible to do so and it's good habit to use them this way. – Onzeq Jun 01 '21 at 01:21
-
I don't recommend using Application settings for such things because dedicated to primitive integral types like bool, integers and enums, or small entities. JSON or SQLite may be better. But if you have a very few buttons... [How to create an application settings parameter of type a list of structs?](https://stackoverflow.com/questions/65848170/how-to-create-an-application-settings-parameter-of-type-a-list-of-structs/65854780#65854780) – Jun 01 '21 at 01:26
-
So if it is better to handle this via SQLite or JSON can you give me solution how to do that with that way please. – Onzeq Jun 01 '21 at 01:46
-
Found that: [How I can save controls created in runtime](https://stackoverflow.com/questions/10739641/how-i-can-save-controls-created-in-run-time-in-windows-forms) and [Saving changes made to controls](https://stackoverflow.com/questions/29857438/saving-changes-made-to-controls-on-form). For using a database it is a broad subject perhaps you need to [learn, try and use](https://zetcode.com/csharp/sqlite) | [How To Use SQLite With C#](https://www.c-sharpcorner.com/article/how-to-use-sqlite-with-c-sharp/). Personally, I use [sqlite-net](https://github.com/praeclarum/sqlite-net) Code-First ORM. – Jun 01 '21 at 02:27
-
@Onzeq: What have you tried so far? – mm8 Jun 01 '21 at 13:27
-
Reply to mm8: Right now I'm just learning SQLite. It seems to solved my problem. – Onzeq Jun 02 '21 at 00:36
-
What reason do you have for creating these at run time? Could you use an item control instead and just bind to the source data? – DaveEP Jun 07 '21 at 22:33