60001528 User defined Table to store application specific user data

Article 60001528
Type Wish
Product Engine
Version 6022
Date Added 10/27/2011 12:00:00 AM
Fixed (4/26/2012 12:00:00 AM)
Submitted by alessio

Summary

User defined Table to store application specific user data

Solution


In version 6023 a new property UserTables was added for vdDocument object


Get the user defined table collection. Used to store application specific user data

You can set user value properties to any of the following type values:
    String Double Int32 Boolean Byte Int16 Int64 UInt16 UInt64 UInt32 Single ushort Enum System.Color VectorDraw.Serialize.IVDHandle
 or any object that implents IVDSerialise interface like default VectorDraw objects(vdFigure , vdPrimary , ByteArray , DoubleArray gPoint gPoints etc.)
 
 By default the collection is empty.
 The object is saved with vdml / vdcl format
 Undo is not supported for VectorDraw.Professional.Table.vdTables object.

Example:

                //group some user property values
                int Int_value = 1;
                double double_value = 1.0d;
                string string_value = "some string data";
                ByteArray bytearray_value = new ByteArray(new byte[] { 1, 2, 3, 4 });
                gPoint gpoint_value = new gPoint(1, 2, 3);
                gPoints gpoints_value = new gPoints(new gPoint[] { new gPoint(1, 2, 3), new gPoint(4, 5, 6) });


                doc.UserTables["Table1"]["Table1_GroupProperties1"]["Integer_Property"] = Int_value;
                doc.UserTables["Table1"]["Table1_GroupProperties1"]["Double_Property"] = double_value;
                doc.UserTables["Table1"]["Table1_GroupProperties1"]["String_Property"] = string_value;
                doc.UserTables["Table1"]["Table1_GroupProperties1"]["ByteArray_Property"] = bytearray_value;


                doc.UserTables["Table2"]["Table2_GroupProperties1"]["gpoint_value"] = gpoint_value;
                doc.UserTables["Table2"]["Table2_GroupProperties2"]["gpoints_value"] = gpoints_value;
               
                //read the user property values that stored before
                Int_value = (int)doc.UserTables["Table1"]["Table1_GroupProperties1"]["Integer_Property"];


                double_value = (double)doc.UserTables["Table1"]["Table1_GroupProperties1"]["Double_Property"] ;
                string_value = (string)doc.UserTables["Table1"]["Table1_GroupProperties1"]["String_Property"];
                bytearray_value = (ByteArray)doc.UserTables["Table1"]["Table1_GroupProperties1"]["ByteArray_Property"];


                gpoint_value = (gPoint)doc.UserTables["Table2"]["Table2_GroupProperties1"]["gpoint_value"];
                gpoints_value = (gPoints) doc.UserTables["Table2"]["Table2_GroupProperties2"]["gpoints_value"];


 
 
Another example that simulates a 2-dimensional sample:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        vdDocument dc { get { return vdFramedControl1.BaseControl.ActiveDocument; } }
        string[,] rowcolumn =  //3 rows x 4 columns string type items array
        { 
            {"00","01","02","03"},//1st row
            {"10","11","12","13"},//2nd row
            {"20","21","22","23"},//3rd row
        };
        private void SaveData_Click(object sender, EventArgs e)
        {
            for (int row = 0; row <= rowcolumn.GetUpperBound(0); row++)
            {
                for (int col = 0; col <= rowcolumn.GetUpperBound(1); col++)
                {
                    dc.UserTables["MyRowColumnData_1"][row.ToString()][col.ToString()] 
                        = rowcolumn[row, col];
                }
                
            }
            dc.SaveAs(System.IO.Path.GetDirectoryName(
                Application.ExecutablePath) + @"\test.vdml");
        }
        private void LoadData_Click(object sender, EventArgs e)
        {
            dc.Open(System.IO.Path.GetDirectoryName(
                Application.ExecutablePath) + @"\test.vdml");
            int nrows = dc.UserTables["MyRowColumnData_1"].Count;
            int ncols = dc.UserTables["MyRowColumnData_1"][0].xProperties.Count;
            Array items = Array.CreateInstance(typeof(string), nrows, ncols);
            for (int row = 0; row < nrows; row++)
            {
                for (int col = 0; col < ncols; col++)
                {
                    items.SetValue(
                        dc.UserTables["MyRowColumnData_1"][row].xProperties[col].PropValue,row,col);
                }
            }
        }
    }

Send comments on this topic.