0

I have searched Google and StackOverflow for an answer - have found related topics, including questions with similr titles, but they seem a bit over my head or unclear.

I'm trying to assign an object as the datasource of a Grid. I'm able to do so by creating a table and writing the values as such:

Do FromVal( 0 ) ToVal( ORD_Array.OrderList.Length - 1 ) Index( IX )  
ORD_Record = ORD_Array.OrderList[IX]  
Ord_BLTz00 = ORD_Record.BLTz00  
Ord_ORDz00 = ORD_Record.ORDz00  
Ord_BLTA00 = ORD_Record.BLTA00  
Ord_SHPA00 = ORD_Record.SHPA00  
Ord_SNAM00 = ORD_Record.SNAM00  

GridView1.DataSource = OrderMem.Dataset.Tables["OrdMf"]  
GridView1.DataBind()  
EndDo  

This works, but I'm sure that I can assign ORD_Record directly as the datasource except first converting it to a valid type - otherwise I receive an error. Can someone explain what I need to do to ORD_Record to convert it to a type that can be bound to the datagrid saving me from creating tables?

competent_tech
  • 44,465
  • 11
  • 90
  • 113
Brian
  • 548
  • 2
  • 8
  • 22

1 Answers1

1

Your code is somewhat confusing with respect to the question. You are looping through all of the record in ORD_Array, but then assigning the grid's datasource on each loop. Also, you have tagged the question as VB.Net, but you are using some syntax that I don't recognize.

However, if you want each of the records in ORD_Array to appear in the grid, then what you need to do is move the GridView1 Dataxxx commands outside of the loop and assign the DataSource to ORD_Array (which probably implements IEnumerable).

If you only want one of the ORD_Records to be assigned to the grid, then you will need to determine how to identify which one in the array should be shown, extract it from the array into an IEnumerable source (you can use a Generic List or even an ArrayList) and then assign that as the DataSource for the GridView.

Update with answer:

You could also try assigning ORD_Array.OrderList directly to the datasource first in case it is enumerable.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • Sorry for the confusion - the code is written in Visual RPG for .Net - VB.Net is the closest to it in syntax. OrderList is an array of objects which are my data rows. Ord_BLTz00 would be a field in the table I created, and I'm writing a row for each object. Assigning it directly gives me the error. Using the generic list is what I'm looking for information on. – Brian Nov 01 '11 at 12:24
  • 1
    I don't know anything about Visual RPG, but in VB.Net, you would Dim cRecords As New System.Collections.Generic.List(Of OrdRecordDataType) (not sure what data type the records in OrderList are), then add each of the records in OrderList to the cRecords collection, then set the gridview datasource to cRecords. You could also try assigning ORD_Array.OrderList directly to the datasource first in case it is enumerable. – competent_tech Nov 01 '11 at 19:02
  • Assigning ORD_Array.OrderList directly to the datasource worked! Thanks for your help! - I'm new at this... – Brian Nov 02 '11 at 15:51
  • I'm glad to hear it worked. I have updated the answer to include the solution. If you wouldn't mind, please click on the checkmark next to the answer so that others will know this resolve the issue for you. Thanks! – competent_tech Nov 02 '11 at 16:29