I have some trials to edit something like any invoice, I found
DataGrid unfamiliar, also
FlexGrid did not have a method to edit, then I created my ActiveX (user control) using
Textbox and hidden
Combobox. I gave the name
KGrid to my ActiveX. I created a project
TestKGrid to test my control. I wrote the code under Visual Studio 2003 and Framework 1.1.
With my ActiveX control, you can:
- Edit any cell in Flex grid
- Delete any row
- Delete all rows and begin with one row
- Add Combo box to any Column
When using my ActiveX control, the Flex grid will begin with one row as
DataGrid control, then increase rows one by one after editing previous row. The grid in my ActiveX control has the name
flxGrid, the Combo box in my ActiveX control has the name
Using the Code
To use my ActiveX
KGrid, you must add the file KFlexgrid.dll to References. You can find this file in the folder TestKGrid\bin\Debug. To add the control to your own form, you have to import it to the toolbox by browsing and adding the item KFlexgrid.dll. When you get it on your toolbox, you just drag it and drop it on your form.
You must add the following files also to References:
These files are in the folder (TestKGrid\bin\Debug).
Suppose the name of our grid control is
kGrid1, we say the name of its grid is
flxGrid and the name of its Combo box is
lstItems. Now we shall write some lines to use the
kGrid1.flxGrid.Cols = 8;
kGrid1.flxGrid.set_ColWidth(1, 2500); kGrid1.lstItems.Width = 120; kGrid1.lstItems.Items.Add ("Cairo, Egypt");
kGrid1.ColCombo = 2;
Points of Interest
I learnt different methods between C# and VB6, as shown in the following examples:
- For column width in VB6, we write:
FlexGrid1.ColWidth(1) = 2500
But in C#, we write:
- View text in the cell at (Row=2) and (Col=3) in VB6, we write:
FlexGrid1.TextMatrix(2, 3) = "any text"
But in C#, we write:
FlexGrid1.set_TextMatrix(2, 3, "any text");
The file TestKGrid.zip contains:
The folder TestKGrid which contains source files.
TestKGrid\bin\Debug\KFlexgrid.dll TestKGrid\bin\Debug\AxInterop.MSFlexGridLib.dll TestKGrid\bin\Debug\Interop.MSFlexGridLib.dll TestKGrid\bin\Debug\ TestKGrid.exe
I write this program to test my Flex grid ActiveX KFlexgrid.dll.
The button <Delete Row> to delete any row under mouse pointer.
The button <Delete All> to delete all rows and begin with one row.
The button <Combo Cell> will add Combo box at third column with the following method:
KGrid1.ColCombo = 2;
But you can add Combo box to any column with code as above after adding some items to the combo box .
I hope my control helps you to edit any table. All friends of CodeProject can use my ActiveX if it is useful.
If you have any ideas, I hope to know and if you find any problem, you can tell me, but in simple English language because my English is poor!
Thanks to CodeProject and to all.
- 26th October, 2007: Initial post