Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

My Flex Grid ActiveX Control

0.00/5 (No votes)
26 Oct 2007 1  
Edit Flex grid with Combo box
Screenshot - KFlex.jpg

Introduction

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 MSFlexGrid, hidden 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

Background

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 lstItems.

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:

  • AxInterop.MSFlexGridLib.dll
  • Interop.MSFlexGridLib.dll

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 KGrid control:

//
// set number of Columns:
// 
kGrid1.flxGrid.Cols = 8;
// 
// set width of second column:
// 
kGrid1.flxGrid.set_ColWidth(1, 2500); // width in Twip as VB6.
// 
// set width to combo box: 
// 
kGrid1.lstItems.Width = 120; // width in Pixel 
// 
// add items to combo box: 
// 
kGrid1.lstItems.Items.Add ("Cairo, Egypt"); 
// 
// add Combo to third column:
//
kGrid1.ColCombo = 2;
//
// delete the row under the mouse pointer:
//
kGrid1.DelRow();
//
// delete all rows and begin with one:
//
kGrid1.DelAll();

Points of Interest

I learnt different methods between C# and VB6, as shown in the following examples:

  1. For column width in VB6, we write:
    FlexGrid1.ColWidth(1) = 2500 

    But in C#, we write:

    FlexGrid1.set_ColWidth(1, 2500); //width in Twip as VB6 
  2. 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");

Remarks

The file TestKGrid.zip contains:

The folder TestKGrid which contains source files.

TestKGrid\bin\Debug\KFlexgrid.dll // this is my Flex grid ActiveX. 
TestKGrid\bin\Debug\AxInterop.MSFlexGridLib.dll // add to References for any Flex grid. 
TestKGrid\bin\Debug\Interop.MSFlexGridLib.dll // add to References for any Flex grid. 
TestKGrid\bin\Debug\ TestKGrid.exe // executable file to test ActiveX. 

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 .

Finally

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.

Mostafa Kaisoun
M_Kaisoun@hotmail.com

History

  • 26th October, 2007: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here