How to create a custom Winform control that supports multiple elements, such as a list

I think I understand the basics of creating user control winforms. I can do Add New and select a user control, and this will give me a design and designer surface file, as well as a code file, etc. And then I can change it to inherit something other than UserControl (like listbox or text box).

Currently, for me, this is completely different: a user control should be a list control (for example, a list) that can be attached to data and with two controls associated with the data (two combined blocks).

I'm not sure where to start? Can anyone refer to a document or some obvious bit in the tools that I am missing, which will make it quick and easy? Any approaches that I can take as an extension of existing control. Any errors I should know about?

Thanks.

Set

EDIT
I decided to use a different approach. However, I leave the question. This is clearly a difficulty than I expected. WPF is not an option for me. Just use the data grid.

+4
source share
3 answers

And then I could change its inheritance from something other than UserControl (like listbox or text box).

Here you make a mistake ... when you exit UserControl, you should not change the inheritance. Inheriting from UserControl gives you the ability to place several different controls on your design surface (for example, a list and two combo boxes). These combined controls make your unique (user) control, which you must give a self-evident name. understand that? It is really simple, very powerful, very reusable, fun, and we use it a lot.

A good reference might be the following: Microsoft walkthrough , MonthPicker (simple)

+3
source

You cannot override the list control according to your requirements. Not so easy. However, there are alternatives:

Since the control has its own events, you can override the render and draw visual characteristics of what looks like a list control. Then you need to create delegates and event handlers so that your control can signal to the rest of the form that something has happened inside it.

The next option is to do the same as I described above, however, using WPF. WPF has more user interface flexibility.

0
source

Create a custom control, add a list and set it to dock = full (or whatever suits your design needs).

override the DataSource property and call a method that will combine the sources into one source and then bind / reinstall this single source in your list.

There are problems with this, but this is one way.

Another is not to create a custom control, but simply combine all your sources into one source, and then bind it to the list control.

WPF will not help in this situation.

0
source

Source: https://habr.com/ru/post/1337372/


All Articles