Solved

can an arraylist have 2 columns?

Posted on 2011-03-22
9
610 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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