Option Explicit
Dim WithEvents dynamicFlexGrid As VBControlExtender
Set dynamicFlexGrid = Controls.Add("MSFlexGridLib.MSFlexGrid.1", ,"FlexGrid1")
With "dynamicVSFlexGrid.object" you can access the FlexGrid object and it's properties/ methods
VBControlExtender object's ObjectEvent event could be also used in VB6 to dynamically add events. But we will let that for another post.With dynamicFlexGrid.object
For r = 1 To .Rows - 1
For c = 1 To .Cols - 1
.TextMatrix(r, c) = "r" & r & "c" & c
Next
Next
dynamicFlexGrid.Height = 300
dynamicFlexGrid.Width = 300dynamicFlexGrid.Visible = True
namespace UpgradeHelpers
{
public class AxControl : AxHost
{
public AxControl(string strCLSID) : base(strCLSID)
{
}
}
public static class ControlExtenderHelper
{
public static AxHost AddExtended(this System.Windows.Forms.Control.ControlCollection controls, Type controlType, string controlName)
{
var newControl = new AxControl(controlType.GUID.ToString());
newControl.Name = controlName;
controls.Add(newControl);
return newControl;
}
public static AxHost AddExtended(this System.Windows.Forms.Control.ControlCollection controls, string progId, string controlName)
{
Type type = Type.GetTypeFromProgID(progId, true);
return AddExtended(controls, type, controlName);
}
}
}
using UpgradeHelpers;
AxHost dynamicVSFlexGrid;
private void button1_Click(object sender, EventArgs e)
{
dynamicFlexGrid = Controls.AddExtended("MSFlexGridLib.MSFlexGrid.1", "FlexGrid1");
dynamic dynamicFlexGrid_object = dynamicFlexGrid.GetOcx();
for (int r = 1; r <= dynamicFlexGrid_object.Rows - 1; r++)
{
for (int c = 1; c <= dynamicFlexGrid_object.Cols - 1; c++)
{
dynamicFlexGrid_object.TextMatrix[r, c] = "r" + r + "c" + c;
}
}
dynamicFlexGrid.Height = 300;
dynamicFlexGrid.Width = 300;
dynamicFlexGrid.Visible = true;
}