Introduction
I made some attempts to make editing the Grid control easy, now this is my new attempt to create an ActiveX control. I give the name (MKGrid
) to my new ActiveX. 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
- After editing cell and leave it, the cell will be saved
- Have more properties and methods
- Use my AcriveX MKGrid in C# and VB.NET with differences in the names of some properties and its parameters
Background
When using my ActiveX control (MKGrid
), the grid begins with one row as Data grid control then increase rows one by one after editing the 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 tables, you can read about some methods and some properties as examples.
In C#
Method/Property | Explanation | Example |
ComboItemsList (ComboCol, ComboList) | Set the List of items [ComboList ] to the Combo box at the Column #ComboCol . | int c = 4;<br />string strList= "Apple/Banana/Orange/Melon/<br />Peach/Strawberry";<br />MKGrid.ComboItemsList(ref c, ref strList); |
DeleteRecord | Deletes the current Record from database file. | MKGrid.DeleteRecord; |
InsertRow | Insert new Row to unbound Grid. | MKGrid.InsertRow; |
set_ColumnHidden(number,ColType) | Returns or sets a value indicating whether a specified column is hide. | MKGrid.set_ColumnHidden(4, false); |
set_ColumnType (number, ColType) | Returns or sets the type of control to show in a column. | MKGrid.set_ColumnType (4, KGrid.grdColumnType.colCheckBox) |
LoadGridByQuery( MyDataFile, GridSQL) | Populate the grid with query [GridSQL ] from the file [MyDataFile ]. | string MyDataFile = <br />Application.StartupPath + @"\DataFiles\" + "test.mdb";<br />string MySql = "SELECT * FROM Customers"<br />MKGrid.LoadGridByQuery(ref MyDataFile, ref MyTable); |
LoadGridFromTable( mdbDataFile, mdbTable) | Bind the Grid to the Table [mdbTable ] from the database file [mdbDataFile ]. | string MyDataFile = Application.StartupPath <br />+ @"\DataFiles\" + "test.mdb";<br />string MyTable = "Customers";<br />MKGrid.LoadGridFromTable<br />(ref MyDataFile, ref MyTable); |
I created a project to test my control, I wrote its code using C# (2003).
You can go back to the source files to read more than the previous examples.
In VB.NET
Method/Property | Explanation | Example |
ComboItemsList (ComboCol, ComboList) | Set the List of items [ComboList ] to the Combo box at the Column #ComboCol . | MKGrid.ComboItemsList (4, "Apple/Banana/Orange/Melon/<br />Peach/Strawberry") |
DeleteRecord | Deletes the current Record from database file. | MKGrid.DeleteRecord |
InsertRow | Insert new Row to unbound Grid. | MKGrid.InsertRow |
ColumnHidden(number,ColType) | Returns or sets a value indicating whether a specified column is hide. | MKGrid.ColumnHidden(5, True) |
set_ColumnType (number, ColType) | Returns or sets the type of control to show in a column. | MKGrid.set_ColumnType (4, KGrid.grdColumnType.colCheckBox) |
LoadGridByQuery( MyDataFile, GridSQL) | Populate the grid with query [GridSQL ] from the file [MyDataFile ]. | Dim MyDataFile As String = Application.StartupPath & "\" & "Test.mdb"<br />Dim MySql As String = "SELECT * FROM Customers"<br />MKGrid.LoadGridByQuery(MyDataFile, MySql) |
LoadGridFromTable( mdbDataFile, mdbTable) | Bind the Grid to the Table [mdbTable ] from the database file [mdbDataFile ]. | Dim MyDataFile As String = <br />StartupPath & "\" & "Test.mdb"<br />Dim MyTable As String = "Customers"<br />MKGrid.LoadGridFromTable (MyDataFile, MyTable) |
I create a project to test my control, I write its code under VisualBasic.NET (2003).
You can go back to the source files to read more than the previous examples.
In VB6
Method/Property | Explanation | Example |
ComboItemsList ComboCol, ComboList | Set the List of items [ComboList ] to the Combo box at the Column #ComboCol . | MKGrid1.ComboItemsList 4, "Apple/Banana/Orange/Melon/<br />Peach/Strawberry" |
DeleteRecord | Deletes the current Record from database file. | MKGrid1.DeleteRecord |
InsertRow | Insert new Row to unbound Grid. | MKGrid1.InsertRow |
ColumnHidden(number) [=Boolean] | Returns or sets a value indicating whether a specified column is hide. | MKGrid1.ColumnHidden(5) = True |
ColumnType(number) [=ColType] | Returns or sets the type of control to show in a column. | MKGrid1.ColumnType(4) = colCheckBox |
LoadGridByQuery MyDataFile, GridSQL | Populate the grid with query [GridSQL ] from the file [MyDataFile ]. | MyDataFile = App.Path & <br />"\" & "Test.mdb"<br />MySql = "SELECT * FROM Customers"<br />MKGrid1.LoadGridByQuery MyDataFile, MySql |
LoadGridFromTable mdbDataFile, mdbTable | Bind the Grid to the Table [mdbTable ] from the database file [mdbDataFile ]. | MyDataFile = App.Path <br />& "\" & "Test.mdb"<br />MyTable = "Customers"<br />MKGrid1.LoadGridFromTable MyDataFile, MyTable |
I created a project to test my control, I wrote its code using Visual Basic 6.
You can go back to the source files to read more than the previous examples.
Using the Code
About columns:
MKGrid.Rows = 2;
MKGrid.Cols = 6;
MKGrid.set_ColHeaderText(1, "Emp ID");
MKGrid.set_ColHeaderText(2, "Emp Name");
MKGrid.set_ColHeaderText(3, "B_Date");
MKGrid.set_ColHeaderText(4, "Salary");
MKGrid.set_ColHeaderText(5, "Married");
MKGrid.set_ColHeaderText(6, "City");
'VB.NET:
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")
MKGrid1.Rows = 2
MKGrid1.Cols = 6
MKGrid1.ColHeaderText(1) = "Emp ID"
MKGrid1.ColHeaderText(2) = "Emp Name"
MKGrid1.ColHeaderText(3) = "B_Date"
MKGrid1.ColHeaderText(4) = "Salary"
MKGrid1.ColHeaderText(5) = "Married"
MKGrid1.ColHeaderText(6) = "City"
About combo box:
int c = 6;
MKGrid.ComboItemsList (ref c, ref strList);
Dim strList String = "Ankara/Berlin/Cairo/London/Los Angeles/Madrid/Marseille/"'_
fill CombBox at column #6 with previous list:MKGrid1.ComboItemsList (6, strList)As
Dim strList String strList = _
"Ankara/Berlin/Cairo/London/Los Angeles/Madrid/Marseille/"
column #6 with previous list:MKGrid1.ComboItemsList (6, strList)
As
About Date Picker and Check box:
Remarks
- When extracting the *.zip files, you can find:
- The ActiveX control KGrid.ocx
- C# Project to test ActiveX
- VB.NET Project to test ActiveX
- VB6 Project to test ActiveX
- Test_EN.mdb, Test_Ar.mdb and MyMarket.mdb
- MKGrid help file
- 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 running the following line:
regsvr32 c:\windows\system32\KGrid.ocx - To add my ActiveX "
MKGrid
" control to your form:
- Open Components dialog, then click Browse
- From its directory or c:\windows\system32\, you can add the
ActiveX
- You can refer to the help file for all methods and properties. If there are any problems, please let me know.
Last Words
I hope this article is useful and helps you to create your applications. If you have any ideas, please tell me. Thanks to CodeProject and thank you all.
Mostafa Kaisoun
m_kaisoun@hotmail.com