ActiveX control using C#



Now I try to use my ActiveX in C#, with my ActiveX control You can:

  • Bind to database file.
  • Add, Edit and delete records.
  • Use Combo box, Date picker and Check box at any column.
  • Add row, delete row, insert row to unbound grid.
  • Hide column, lock column, resize column and sort column.
  • Save unbound grid after edit it as *.mdb file or *.htm file.
  • More properties and methods.

How it works

When using my ActiveX control (MKGrid) the grid begins with one row as Data grid control then increase rows one by one after edit current row.

When you bind the grid with database file, my ActiveX will look for the Date field, if any then put Date picker at the Date column, also my ActiveX will look for the Boolean field (Yes, No), if any then put Check box at the Boolean column without user intervention, this means that the user does not need to specify the type field in this case.

In the following table you can read about some Methods and some properties as examples:
 

Method/Property

Explanation

Example

ComboItemsList
(ComboCol, ComboList)

Set the List of items [ComboList] to the Combo box at the Column #ComboCol.

int c = 4;
string strList= "Apple/Banana/Orange/Melon/Peach/Strawberry";
MKGrid1.ComboItemsList(ref c, ref strList);

DeleteRecord

Deletes the current Record from database file.

MKGrid1.DeleteRecord;

InsertRow

Insert new Row to unbound Grid.

MKGrid1.InsertRow;

set_ColumnHidden
(number,ColType)

Returns or sets a value indicating whether a specified column is hide.

MKGrid1.set_ColumnHidden(4, false);

set_ColumnType
(number, ColType)

Returns or sets the type of control to show in a column.

MKGrid1.set_ColumnType (4, KGrid.grdColumnType.colCheckBox)

LoadGridByQuery
(MyDataFile, GridSQL)

Populate the grid with query [GridSQL] from the file [MyDataFile].

string MyDataFile = Application.StartupPath + @"\DataFiles\" + "test.mdb";
string MySql = "SELECT * FROM Customers"
MKGrid1.LoadGridByQuery(ref MyDataFile, ref MyTable);

LoadGridFromTable
(mdbDataFile, mdbTable)

Bind the Grid to the Table [mdbTable] from the database file [mdbDataFile].

string MyDataFile = Application.StartupPath + @"\DataFiles\" + "test.mdb";
string MyTable = "Customers";
MKGrid1.LoadGridFromTable(ref MyDataFile, ref MyTable);


You can read about more Methods and Properties in my test project.

Examples

About columns:


            MKGrid1.Rows = 2; // number of rows
            MKGrid1.Cols = 6; // number of columns
            // Set Header of column:
            MKGrid1.set_ColHeaderText(1, "Emp ID");
            MKGrid1.set_ColHeaderText(2, "Emp Name");
            MKGrid1.set_ColHeaderText(3, "B_Date");
            MKGrid1.set_ColHeaderText(4, "Salary");
            MKGrid1.set_ColHeaderText(5, "Married");
            MKGrid1.set_ColHeaderText(6, "City");


About combo box:


            // items list for Combo box.
            // we are using the slash "/" as delimiter between items.
            int c = 6;
            string strList = "Ankara/Berlin/Cairo/London/Los Angeles/Madrid/Marseille/";
            // fill CombBox at column #6 with previous list:
            MKGrid1.ComboItemsList(ref c, ref strList);


About Date Picker and Check box:


            // Set Date Picker and Check box:
            MKGrid1.set_ColumnType(3, KGrid.grdColumnType.colDateControl); // Date control at column #3
            MKGrid1.set_ColumnType(5, KGrid.grdColumnType.colCheckBox); // CheckBox at column #5


Remarks

I create project to test my control, I write the code under C# (2003). You can go back to source files to read more than previous examples.

When extract the file MKGrid_C.zip You can find:
  • The ActiveX control KGrid.ocx
  • C# Project to test ActiveX with six forms as examples.
  • Test_EN.mdb, Test_Ar.mdb and MyMarket.mdb.
  • MKGrid help file.
Please:
  1. Set my ActiveX "KGrid.ocx" in your program directory, but it is better if you set it in the directory:
    "c:\windows\system32\" then register the ActiveX control by run the following line:
    regsvr32 c:\windows\system32\KGrid.ocx
  2. To add my ActiveX "MKGrid" control to your form:
    - open Com Components dialog then click Browse
    - from your program directory, or from (c:\windows\system32) you can add the ActiveX.
  3. You can refer to the help file for all methods and properties. If there are any problems please let me know.

I hope this article is useful and helps You to create your applications. If you have any idea, please tell me. Thanks for all.


Similar Articles