Click here to Skip to main content
15,885,782 members
Articles / Programming Languages / C#

My Flex Grid ActiveX Control

Rate me:
Please Sign up or sign in to vote.
3.57/5 (5 votes)
26 Oct 2007CPOL2 min read 64.8K   2.4K   17   6
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:

C#
//
// 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:
    VB.NET
    FlexGrid1.ColWidth(1) = 2500 

    But in C#, we write:

    C#
    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:
    VB.NET
    FlexGrid1.TextMatrix(2, 3) = "any text" 

    But in C#, we write:

    C#
    FlexGrid1.set_TextMatrix(2, 3, "any text");

Remarks

The file TestKGrid.zip contains:

The folder TestKGrid which contains source files.

C#
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:

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Egypt Egypt
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Rakesh Aytha10-Nov-11 17:53
Rakesh Aytha10-Nov-11 17:53 
GeneralMultiple Combo Pin
notiboy217-Dec-07 2:25
notiboy217-Dec-07 2:25 
GeneralRe: Multiple Combo Pin
Mostafa Kaisoun10-Dec-07 12:02
Mostafa Kaisoun10-Dec-07 12:02 
QuestionMore than 1 combobox ? Pin
notiboy2130-Nov-07 23:12
notiboy2130-Nov-07 23:12 
AnswerRe: More than 1 combobox ? Pin
Mostafa Kaisoun1-Dec-07 11:24
Mostafa Kaisoun1-Dec-07 11:24 
GeneralRe: More than 1 combobox ? Pin
notiboy211-Dec-07 14:26
notiboy211-Dec-07 14:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.