Algorithm for creating the list, set the type and presentation, inclusion of data

As ObjectListView is not used to display data from DB, the standard way to display a list of objects created directly in code, no.

However, there is an algorithm solving this problem.

The algorithm for adding data

  • Create a list of data to display.
  • To install ObjectListView the type and performance.
  • Set LimitFunction to base nothing podgruzilo.
  • Call method SetObjects.

To create a data list

First, create a proper list of the data that must be downloaded into ObjectListView. Not necessarily that the data was in the database.

For example, the variable myObjects to which to save the created objects list.

Setting the type and presentation

For example, to display objects of type Адрес representation АдресL.

In the code ostanavlivajutsja settings ObjectListView:

objectListView1.DataObjectTypes = new[] { typeof(Адрес) };
objectListView1.ViewName = "АдресL";

Lock uploading data from the database

To get data from database is not loaded during the update (pressing the button Refresh), you need to install LimitFunction have ObjectListView so that the condition is never fulfilled. For example, in the following way:

objectListView1.LimitFunction = FunctionBuilder.BuildFalse();

Adding objects to the list

To add objects to the list, simply call the method SetObjects have ObjectListView:


However, if you call this method at the time of creation of the form, the data will be lost when you press the button Refresh.

To data is persisted, you must call this method after loading data from the database. For this, you need to subscribe to an event AfterFillData and add in a handler method call SetObjects, for example so:

objectListView1.AfterFillData += (o, s) =>