473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

What's the MappingName for a Collection?

I bind a collection to a data grid, and it works okay, but when I try to
create customized columns, it just doesn't work. Here is the code. Note
that if I uncomment that section below, and use "DT" as the mapping
name, it works fine. But I don't want to have to copy the collection to
the data table every time.

I searched Google and keep reading that you have to use "the classname
of the collection," but nothing I use as a mapping name gives me any
results. I just get a blank datagrid. Thanks for any suggestions.

=== code

Module x
Global objElecMotor as clsElecMotor
Global ElecMotors As New Collection()
End Module

Public Class frmList
Inherits System.Windows.Forms.Form

Private Sub frmList_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Dim Column1 As New DataGridTextBoxColumn()
Column1.MappingName = "MotorID"
Column1.HeaderText = "ID"
Column1.Width = 40

Dim Column2 As New DataGridTextBoxColumn()
Column2.MappingName = "Description"
Column2.HeaderText = "Desc"
Column2.Width = 100

Dim Column3 As New DataGridTextBoxColumn()
Column3.MappingName = "RPM"
Column3.HeaderText = "RPM"
Column3.Width = 40

Dim Column4 As New DataGridTextBoxColumn()
Column4.MappingName = "Voltage"
Column4.HeaderText = "Volts"
Column4.Width = 30

Dim Column5 As New DataGridTextBoxColumn()
Column5.MappingName = "Status"
Column5.HeaderText = "STS"
Column5.Width = 40

Dim NewStyle As New DataGridTableStyle()
NewStyle.MappingName = "?????????????"
NewStyle.GridColumnStyles.Add(Column1)
NewStyle.GridColumnStyles.Add(Column2)
NewStyle.GridColumnStyles.Add(Column3)
NewStyle.GridColumnStyles.Add(Column4)
NewStyle.GridColumnStyles.Add(Column5)

'Dim dt As New DataTable("DT")
'dt.Columns.Add("MotorID", Type.GetType("System.String"))
'dt.Columns.Add("Description", Type.GetType("System.String"))
'dt.Columns.Add("RPM", Type.GetType("System.Int32"))
'dt.Columns.Add("Voltage", Type.GetType("System.Int32"))
'dt.Columns.Add("Status", Type.GetType("System.String"))

'Dim obj As clsElecMotor
'For Each obj In ElecMotors
' dt.Rows.Add(New Object() {obj.MotorID, obj.Description, _
obj.RPM, obj.Voltage, obj.Status})
'Next
'DataGrid.DataSource = dt

DataGrid.TableStyles.Clear()
DataGrid.TableStyles.Add(NewStyle)
End Sub

Nov 20 '05 #1
2 1472
Hi,

Use Arraylist as the mappingname if you are binding to an arraylist.
Use Collection if you are binding to a collection. Remeber the datagrid will
only show properties.

Dim arBind As New Collection

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim x As Integer

For x = 0 To 20

Dim cls As New BindTo

cls.Col1 = x.ToString

cls.Col2 = Chr(65 + x)

arBind.Add(cls)

Next

SetupGrid()

DataGrid1.DataSource = arBind

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Collection"

Dim colDescription As New DataGridTextBoxColumn

With colDescription

..MappingName = "Col2"

..HeaderText = "Description"

..Width = 240

..NullText = ""

End With

Dim colQty As New DataGridTextBoxColumn

With colQty

..MappingName = "Col1"

..HeaderText = "Qty"

..Width = 50

End With

ts.GridColumnStyles.Add(colDescription)

ts.GridColumnStyles.Add(colQty)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colQty = Nothing

colDescription = Nothing

End Sub

End Class

Public Class BindTo

Private mstrCol1 As String

Private mstrCol2 As String

Public Property Col1() As String

Get

Return mstrCol1

End Get

Set(ByVal Value As String)

mstrCol1 = Value

End Set

End Property

Public Property Col2() As String

Get

Return mstrCol2

End Get

Set(ByVal Value As String)

mstrCol2 = Value

End Set

End Property

End Class

Ken
--------------
"tr****@sirius.com.no.more" <us**@example.com> wrote in message
news:bg********************************@news.super news.com...
I bind a collection to a data grid, and it works okay, but when I try to
create customized columns, it just doesn't work. Here is the code. Note
that if I uncomment that section below, and use "DT" as the mapping
name, it works fine. But I don't want to have to copy the collection to
the data table every time.

I searched Google and keep reading that you have to use "the classname
of the collection," but nothing I use as a mapping name gives me any
results. I just get a blank datagrid. Thanks for any suggestions.

=== code

Module x
Global objElecMotor as clsElecMotor
Global ElecMotors As New Collection()
End Module

Public Class frmList
Inherits System.Windows.Forms.Form

Private Sub frmList_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Dim Column1 As New DataGridTextBoxColumn()
Column1.MappingName = "MotorID"
Column1.HeaderText = "ID"
Column1.Width = 40

Dim Column2 As New DataGridTextBoxColumn()
Column2.MappingName = "Description"
Column2.HeaderText = "Desc"
Column2.Width = 100

Dim Column3 As New DataGridTextBoxColumn()
Column3.MappingName = "RPM"
Column3.HeaderText = "RPM"
Column3.Width = 40

Dim Column4 As New DataGridTextBoxColumn()
Column4.MappingName = "Voltage"
Column4.HeaderText = "Volts"
Column4.Width = 30

Dim Column5 As New DataGridTextBoxColumn()
Column5.MappingName = "Status"
Column5.HeaderText = "STS"
Column5.Width = 40

Dim NewStyle As New DataGridTableStyle()
NewStyle.MappingName = "?????????????"
NewStyle.GridColumnStyles.Add(Column1)
NewStyle.GridColumnStyles.Add(Column2)
NewStyle.GridColumnStyles.Add(Column3)
NewStyle.GridColumnStyles.Add(Column4)
NewStyle.GridColumnStyles.Add(Column5)

'Dim dt As New DataTable("DT")
'dt.Columns.Add("MotorID", Type.GetType("System.String"))
'dt.Columns.Add("Description", Type.GetType("System.String"))
'dt.Columns.Add("RPM", Type.GetType("System.Int32"))
'dt.Columns.Add("Voltage", Type.GetType("System.Int32"))
'dt.Columns.Add("Status", Type.GetType("System.String"))

'Dim obj As clsElecMotor
'For Each obj In ElecMotors
' dt.Rows.Add(New Object() {obj.MotorID, obj.Description, _
obj.RPM, obj.Voltage, obj.Status})
'Next
'DataGrid.DataSource = dt

DataGrid.TableStyles.Clear()
DataGrid.TableStyles.Add(NewStyle)
End Sub

Nov 20 '05 #2
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote:
Use Arraylist as the mappingname if you are binding to an arraylist.
Use Collection if you are binding to a collection.


Thanks for the code. I've checked that it does what I want, and now I'll
see why my code doesn't.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
7
by: _e_ | last post by:
I'm trying to set custom widths and headings for DataGrid columns, but they keep displaying as defaults. I did configure the params via the TableStyles collection -> ColumnStyles collection. ...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
3
by: ad | last post by:
Hi, When I studied CSharp, I am confuse by IList, Collection and Array. What is the relationships between them?
7
by: Mike Fellows | last post by:
Below is my code that is carried out on my dataset, datagrid etc... Im trying to get column0 "Date & Time" to show date and time, not just date ive read some stuff posted by Dmitriy Lapshin on...
0
by: DraguVaso | last post by:
Hi, I have in my VB.NET-application a DataGrid with two DataTables in with a Parent-Child-relationship defined. When the users clicks on a call in the DataGrid, i want to know the MappingName...
14
by: Rich | last post by:
Yes, I need to store some values in an array type collection object that can hold 3 or more parameters per index. I have looked at the collection object, hashtable object and would prefer not to...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
1
by: fiaolle | last post by:
Hi The first set of source code is the class for a combobox in a grid, hopefully. In the second set of code we try to use the combobox class, but the grid is empty. I don't understand how this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.