Solved

can an arraylist have 2 columns?

Posted on 2011-03-22
9
608 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
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
Industry Leaders: 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!

 

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 500 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Technology Resume 7 66
Generate Unique ID in VB.NET 21 99
Is it possible to preview ajax call before submitting to the database? 18 59
ASP.NET MVC - Views 3 38
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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