I have an ActiveX dll written in VB6. It exposes a class called
CustomerDisplays, with a Public Function NewEnum (procedure ID -4,
hide this member), and a Public Function Item (default) and a Public
Function Count. IOW, this thing looks like an enumerable collection
of, in this case, CustomerDisplay objects. Each CustomerDisplay object
has, in turn, an lCustomerID as Long property and a sSortName as
String property. The CustomerDisplays objects works fine as an
enumberable collection in VB6, VBA, and VB.Net. Used it for years.
I am trying to build an asp.net page with a DataGrid control bound to
a CustomerDisplays object. My form code is shown below. When I run it,
I get an "Index was out of range" error on the line that references
Columns(0). The DataGrid isn't creating any columns.
Can someone tell me what I'm doing wrong? Is the correct way to bind a
DataGrid to a legacy COM component?
========code=================
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid
Public moCustomerDisplays As WhsBusObjectsTLB.CustomerDisplays
Public moCustomerDisplay As WhsBusObjectsTLB.CustomerDisplay
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Me.IsPostBack Then
moCustomerDisplays = New
WhsBusObjectsTLB.CustomerDisplays()
With Me.DataGrid1
.DataSource = moCustomerDisplays
.DataKeyField = "lCustomerID"
.AutoGenerateColumns = True
.DataBind()
.Columns(0).Visible = True
.Columns(1).Visible = True
End With
End If
End Sub
End Class