Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

can an arraylist have 2 columns?

Posted on 2011-03-22
9
Medium Priority
?
612 Views
Last Modified: 2012-05-11
I am scanning inventory into a datagrid and in the process getting some information on each item.  I'd like to have 2 separate columns but can't seem to get this to work with an array list.  I am kind of new to array's.  is this possible or should I do this an easier way.  i am displaying the data in Gridviewer on Visual studio 2005.  thanks.


    Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Dim ItemList As New ArrayList()
        Dim strSql1 As String = ""
        Dim strOrigValue As String = TextBox1.Text

        If Not Session.Item("sessItemList") Is Nothing Then
            ItemList = Session("sessItemList")
        End If

        If TextBox1.Text <> "" Then

            strSql1 = "select top 1 ITEMNMBR from IV00200 where SERLNMBR like '%02608520462%'"    ' for example use only '
            TextBox1.Text = TextBox1.Text & " || " & exExecuteScalar(strSql1)

            If ItemList.Contains(TextBox1.Text) Then
                lblError2.Text = "Error! Duplicate Values are not allowed."
            Else
                ItemList.Add(TextBox1.Text)
                lblError2.Text = ""
            End If

        End If

        Session("sessItemList") = ItemList

        GridView1.DataSource = Session("sessItemList")
        GridView1.DataBind()

        TextBox1.Text = ""
        TextBox1.Focus()

    End Sub
0
Comment
Question by:purdyra1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35188577
using datatable would be an easy approach for that.
eg,

// Here we create a DataTable with four columns.

	DataTable table = new DataTable();
	table.Columns.Add("Dosage", typeof(int));
	table.Columns.Add("Drug", typeof(string));
	table.Columns.Add("Patient", typeof(string));
	table.Columns.Add("Date", typeof(DateTime));

	//
	// Here we add five DataRows.
	//
	table.Rows.Add(25, "Indocin", "David", DateTime.Now);
	table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
	table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
	table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
	table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
	

Open in new window


0
 
LVL 10

Expert Comment

by:khan_webguru
ID: 35188662
Hello Bro!

I did that in past by the help of this code:

 
Public Class withPICS
    Dim _pic As system.byte
    Dim _id As integer
 
    Sub New(ByVal pic As system.byte, ByVal id As integer)
        _pic = pic
        _id = id
    End Sub
 
    Public ReadOnly Property pic() As system.byte
        Get
            Return _pic
        End Get
    End Property
 
    Public ReadOnly Property id() As integer
        Get
            Return _id
        End Get
    End Property
End Class
 
xarray.ADD(new withPICS(myreader.getvalue(0), myreader.getvalue(1))
mydatagridview.datasource = xarray '''displays

Open in new window


I Think

xarray.item(i) .pic() ' would get the picture
xarray.item(i).id()  ' would get the id

PS. Using the class withPICS will take up more memory then two arrays, and will run slower.


Hope this example will help u to fix ur problem.

Regards,

Asif Ahmed Khan
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35188721
Hi,
You can use some of your Custom class and then use ArrayList of that objects. as following

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Dim ItemList As New ArrayList()
        Dim strSql1 As String = ""
        Dim strOrigValue As String = TextBox1.Text

        If Not Session.Item("sessItemList") Is Nothing Then
            ItemList = Session("sessItemList")
        End If

        If TextBox1.Text <> "" Then

            strSql1 = "select top 1 ITEMNMBR from IV00200 where SERLNMBR like '%02608520462%'"    ' for example use only '
            TextBox1.Text = TextBox1.Text & " || " & exExecuteScalar(strSql1)

            Dim data As MyDataClass = New MyDataClass(TextBox1.Text, "someothe data from qry")

            If ItemList.Contains(data) Then
                lblError2.Text = "Error! Duplicate Values are not allowed."
            Else
                ItemList.Add(data)
                lblError2.Text = ""
            End If

        End If

        Session("sessItemList") = ItemList

        GridView1.DataSource = Session("sessItemList")
        GridView1.DataBind()

        TextBox1.Text = ""
        TextBox1.Focus()

    End Sub

and here is your custom class
Public Class MyDataClass

    Public Sub New()

    End Sub

    Public Sub New(ByVal v1 As String, ByVal v2 As String)
        Val1 = v1
        Val2 = v2
    End Sub
    Public Val1 As String
    Public Val2 As String

End Class

Make sure you define and assign column to correct datafield in the gridview
Thanks
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:purdyra1
ID: 35192069
Thank you to all...

IJZ:
I tried your approach but I am getting an error.

ERROR:  
error:
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
Additional information: A field or property with the name '03712758111 || BS_NOK_BX' was not found on the selected data source.

here is the gridview info I have that I inserted into the code you gave me.:


        Dim bf As New BoundField
        bf.DataField = "Val1"
        GridView1.Columns.Add(bf)

        GridView1.DataSource = Session("sessItemList")(0)
        GridView1.DataBind()
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35192302
GridView1.DataSource = Session("sessItemList")
instead of GridView1.DataSource = Session("sessItemList")(0)
0
 

Author Comment

by:purdyra1
ID: 35192358
I changed it (I did try it before as well) and now I am getting:

Additional information: A field or property with the name 'Val1' was not found on the selected data source.

also, here is what I am seeing in the command window

>? Session("sessItemList")(0).Val1

"03712758738 || BS_NOK2125HS_BX" {String}
    String: "03712758738 || BS_NOK2125HS_BX"
0
 
LVL 16

Accepted Solution

by:
Imran Javed Zia earned 2000 total points
ID: 35192415
ok,
please change class with following

Public Class MyDataClass

    Public Sub New()

    End Sub

    Public Sub New(ByVal v1 As String, ByVal v2 As String)
        Val1 = v1
        Val2 = v2
    End Sub
    Public Property Val1() As String
        Get
            Return _Val1
        End Get
        Set(ByVal value As String)
            _Val1 = value
        End Set
    End Property

    Public Property Val2() As String
        Get
            Return _Val2
        End Get
        Set(ByVal value As String)
            _Val2 = value
        End Set
    End Property



    Public _Val1 As String
    Public _Val2 As String

End Class
0
 

Author Closing Comment

by:purdyra1
ID: 35198638
Works great now, thanks for your help.
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35198657
you are most welcome
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question