Home Page > Programming Samples and Tutorials > .NET Samples > C# Samples > User Data
C# UserData Sample
User Data C# Sample
User Data Sample demonstrates programmatic access to the data table stored in
KernelCAD models .
Running the application
On start the application displays names of all object in the model
irrespectively to child/parent relation in the "All objects"
list.
If during the load the displayed model does not have a data table the table
is created. The newly created table has tree fields in each record and one
record per each object in the model. The fields are:
- Index of the object in the Flat Object Array,
which serves as a link of object to record. Type: long
- Description of the object. Type: string. Default length.40.
- Weight of the object. Type: double.
The "Selected Object" group of
controls displays above fields for the object currently selected in the "All objects"
list.
Pressing the Enter button will modify the record. Note that to make changes
permanent the model has to be saved before closing the application.
Implementation
All activity starts with the UserDataForm.UpdateModelInfo(), which is called
either on start of the application or on load of a new model. In this function IDataSource
is queried from IModel. Existence of the data
table in the model is checked with IDataSource.GetTable.
If the table exists its IData interface is acquired
and stored in _iTableData variable. Otherwise the table is created in
UserDataForm.CreateTable(), where the three fields described above are added.
Newly created table is populated than with records one per each object in the
model. It is done. in UserDataForm.CreateRecords() function using IRecordSet.InsertRecordAt
and IDataMods
interface.
An individual record is displayed on changes of selection in the list box in
UpdateObjectInfo() and DisplayDataBaseObjectInfo() functions using IData
and IUserData interface.
OnEnter() handler looks up the selected object in the Flat Object Array
and uses the index as key (the first field) into the data base to modify the
record with calls to IDataMods.SetStringAt
and IDataMods.SetDoubleAt
methods.
See also User Data, C# Samples, All samples.
|