Solved

can an arraylist have 2 columns?

Posted on 2011-03-22
9
604 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now