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
Solved

How to pass data from Listbox and Grid to a textbox

Posted on 2012-04-04
11
444 Views
Last Modified: 2012-04-30
Hello,

I am using the code below to pass the data from my textbox to multiple rows of my listbox.

C1NSN.Text = dtNSN.Rows(0).Item("NSN")
        Dim tmp() As String = C1NSN.Text.split(";")
        For i As Integer = 0 To tmp.Length - 1
            'ListBox1.Items.Add(tmp(i))
             GridView1.??????
        Next


How do I also pass it to a Gridview?

Victor
0
Comment
Question by:vcharles
  • 7
  • 3
11 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37805574
Do:
GridView1.Rows.Add(tmp(i))

Open in new window

0
 

Author Comment

by:vcharles
ID: 37806178
I tried it with the regular Gridview that comes with VS and received the following error:

"Add is not a member of  System.We.UI.Webcontrols.GridViewRowCollection"

When I treid the Gridview from ComponentOne, I received the following error:

"Is not accessible in this content because it is Friend"

Any ideas how to fix this problem?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37807635
You can use a DataTable, fill it and then set it as datasource of grid.

C1NSN.Text = dtNSN.Rows(0).Item("NSN")
        Dim tmp() As String = C1NSN.Text.split(";")
        Dim dTable As New DataTable
        dTable.Columns.Add("Column1", GetType(String))
        For i As Integer = 0 To tmp.Length - 1
            'ListBox1.Items.Add(tmp(i))
             dTable.Rows.Add(new object() { tmp(i) })
        Next
        Gridview1.DataSource = dTable
        Gridview1.Databind()

Open in new window

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:vcharles
ID: 37807767
That is a great idea. I will try it and get back to you.
Thanks.
0
 

Author Comment

by:vcharles
ID: 37807940
It worked, but I got the following error when using the code with my third party control.

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

The error ocurrs on this function:

   function Sys$WebForms$PageRequestManager$_endPostBack(error, executor, data) {
        if (this._request === executor.get_webRequest()) {
            this._processingRequest = false;
            this._additionalInput = null;
            this._request = null;
        }
        var handler = this._get_eventHandlerList().getHandler("endRequest");
        var errorHandled = false;
        if (handler) {
            var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
            handler(this, eventArgs);
            errorHandled = eventArgs.get_errorHandled();
        }
        if (error && !errorHandled) {
            throw error; 'Error********************
        }
    }

When I used the regular Grid, it worked but I am unable to edit data and I don't see a property to the edit property. How do I set the edit property to true and How do I remove the column header.

Any ideas why I am getting the error with the third party control?

Thanks.
0
 

Author Comment

by:vcharles
ID: 37808131
Just realised I can use a string rather than a textbox, below is my latest code, but I still have the same issues mentioned in the previous post.
           Dim s as string
           s = "1.;2.;3.;4.;5."
            Dim tmp() As String = s.Split(";")
            Dim dTable As New DataTable
            dTable.Columns.Add("Column1", GetType(String))
            For i As Integer = 0 To tmp.Length - 1
                dTable.Rows.Add(New Object() {tmp(i)})
            Next
            GridView1.DataSource = dTable
            GridView1.DataBind()
            GridView1.Caption = False
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37810492
No idea why would you get that error. So the data displays as expected when using a standard grid? That means there is no problem with the above code.
0
 

Author Comment

by:vcharles
ID: 37810681
Using the regular Grid, how do you set the Grid to edit mode, and as mentioned in a nother post I ran into other issues with passing the data to a textbox.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37811965
For Gridview, you need to set the edititemindex of the grid and you can only edit one row at a time? Do you want to go that route?
0
 

Author Comment

by:vcharles
ID: 37812131
Yes. I will enter the data and see if I can pass it to a text box. Thanks.
0
 

Author Comment

by:vcharles
ID: 37812241
I tried GridView1.EditIndex = True but still unable to add data in the rows.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Connection String through a VPN 8 53
parsing JSON help 1 20
VS 2015 is giving [No relevant source lines] 2 24
reading excel file in .net 2 14
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

808 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