DTFan
New member
- Joined
- Apr 12, 2005
- Messages
- 2
- Programming Experience
- Beginner
OK. I am **hoping** this is something silly and simple that I'm forgetting to do. I've read some examples on binding a datagrid to an array list and that is what I'm now trying to do. I've got an ArrayList (populated from a structure). I've got the MappingName set to the ArrayList name (which I believe is what I'm supposed to do). I've got each of the items in the ArrayList all as a String which I've also read is necessary (all the ArrayList items have to be of the same type). But I'm not getting a datagrid with the information in it.
Here's what I've got so far ... can anyone see where I'm going wrong?
I am lost at this point. I get nothing but a gray box when I run the code. I am REALLY hoping that it is something simple that I'm missing. As always, any and all help is greatly appreciated.
Thanks in advance.
Here's what I've got so far ... can anyone see where I'm going wrong?
VB.NET:
[font=Courier New][color=#006400]' structure which will be loaded into the array[/color]
[color=blue]Public[/color] Structure Data
[color=blue] Public[/color] _ID [color=blue]As Integer[/color]
[color=blue]Public[/color] _dt [color=blue]As[/color] DateTime
[color=blue]Public[/color] _text1 [color=blue]As String[/color]
[color=blue]Public[/color] _num [color=blue]As[/color] Decimal
[color=blue]Public[/color] _text2 [color=blue]As String[/color]
[color=blue]Public[/color] _text3 [color=blue]As String[/color]
[color=blue]Public[/color] _state [color=blue]As Boolean[/color]
[color=blue]Public[/color] [color=blue]Sub[/color] [color=blue]New[/color]([color=blue]ByVal[/color] id, [color=blue]ByVal[/color] dt, [color=blue]ByVal[/color] text1, [color=blue]ByVal[/color] num, _
[color=blue]ByVal[/color] text2, [color=blue]ByVal[/color] text3, [color=blue]ByVal[/color] state)
_ID = id
_dt = dt
_Text1 = text1
_num = num
_text2 = text2
_text3 = text3
_state = state
[color=blue]End[/color] [color=blue]Sub[/color]
[color=blue]End[/color] Structure
[color=darkgreen]' this is where I add the structure to the arraylist and then call[/color]
[color=darkgreen]' the procedure to display the arraylist in the datagrid[/color]
[color=blue]Private[/color] [color=blue]Sub[/color] AddLIArrayItem()
[color=blue]Dim[/color] temp [color=blue]As[/color] [color=blue]New[/color] Data(intServID.ToString, TextBox1.Text.ToString, _
TextBox2.Text.ToString, TextBox3.Text.ToString, _
TextBox4.Text.ToString, TextBox5.Text.ToString, _
Check1.checked.ToString)
arrlstFullList.Add(temp)
BindArrayListToGrid()
[color=blue]End[/color] [color=blue]Sub[/color]
[color=blue]Private[/color] [color=blue]Sub[/color] BindArrayListToGrid()
DataGrid1.DataSource = arrlstLineItems
[color=blue]Dim[/color] ts1 [color=blue]As[/color] DataGridTableStyle
ts1 = [color=blue]New[/color] DataGridTableStyle
ts1.MappingName = "arrlstFullList"
[color=blue]Dim[/color] col0 [color=blue]As[/color] DataGridTextBoxColumn
col0 = [color=blue]New[/color] DataGridTextBoxColumn
[color=blue]With[/color] col0
.MappingName = "_ID"
.Width = 65
[color=blue]End[/color] [color=blue]With[/color]
ts1.GridColumnStyles.Add(col0)
[color=blue]Dim[/color] col1 [color=blue]As[/color] DataGridTextBoxColumn
col1 = [color=blue]New[/color] DataGridTextBoxColumn
[color=blue]With[/color] col1
.MappingName = "_dt"
.Width = 65
[color=blue]End[/color] [color=blue]With[/color]
ts1.GridColumnStyles.Add(col1)
[color=darkgreen]' I have code for the next 5 columns (numbers 2 - 6) listed[/color]
[color=darkgreen]' here but since they are all the same (just diff. widths) other[/color]
[color=darkgreen]' than the mappingname, I figured I would just list the first[/color]
[color=darkgreen]' two. For each of the columns I do change the .MappingName[/color]
[color=darkgreen]' to match the structure name for that item (_ID, _text1, _num,[/color]
[color=darkgreen]' etc.)[/color]
DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts1)
[color=blue]End[/color] [color=blue]Sub[/color][/font]
I am lost at this point. I get nothing but a gray box when I run the code. I am REALLY hoping that it is something simple that I'm missing. As always, any and all help is greatly appreciated.
Thanks in advance.