开发者

Allowing to Customize (Add/Remove) ListView Columns and Add/Edit the records (WinForm)

I have an Employee class ( Id,Name,Age) with few objects. I am showing all the records in "Employee View" form using ListView control and allowing user to Add/Edit/Delete these records. And have separate Form to Add a new record or to edit an existing one. (No database interaction, just have a List to persist these changes)

Now, I want to support this setup (Employee View => Add/Edit Employee) with a Customizable number of columns (by default, showing the columns as per fields in my Employee object). So that, if user wants to send in more info开发者_开发知识库rmation (like, DoB for example) then he should be able to add that column in ListView and Add/Edit Employee forms should show one appropriate control for each column ( example DateTimePicker for DoB) to add/edit a desired record.

Thanks in advance.


From memory the standard WinForms ListView control does not provide built-in data-binding. I would suggest that you are better off using the DataGridView in bound mode. That will give you the functionality where fields in the data source automatically appear as columns in the DataGridView.

The DataGridView also provides built-in editing of rows. This editing is "in-place" in the DataGridView itself, so this may not be ideal for certain types of applications. However you can disable in-place editing (using the ReadOnly and AllowUserToAddRows properties) and continue to display a separate add/edit form if required.

In your add/edit form, a common way to do what you ask is to add controls dynamically to form according to the number of fields in the data source. This involves creating the controls in code, setting position and format properties and then passing them to Form.Controls.Add(). You can then populate these fields manually or possibly use Simple Data Binding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜