Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / April 2004

Tip: Looking for answers? Try searching our database.

Error message when binding a listbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JR - 30 Apr 2004 17:51 GMT
I am attempting to display two list boxes. In the first list box is a listing of all entities. When a entity is selected and it has a subentity the second list box displays with a list of the subentities. The code works but I get an error at the following two steps: (Code is VB.Net on a form

'set the data source to the data set's table SubEntit
           lstSubEntity.DataSource = dsData.Tables("SubEntity"

'display the columns subentity nam
           lstSubEntity.DisplayMember = ("EntityName"

The error I receive is: Cast from type 'DataRowView' to type 'String' is not valid

Here is the entire code
Private Sub lstEntity_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntity.SelectedIndexChange

                      'define a new data adapte
           Dim daSubEntity As SqlClient.SqlDataAdapte

           'using the new data adapter attempt to locate in the database table tblSubEntity a subentity for the selected entity
           daSubEntity = New SqlClient.SqlDataAdapter("SELECT * FROM tblSubEntity WHERE Status = 1  AND CustomerID = " & lstEntity.SelectedValue & " ORDER BY EntityName", conn

           'fill the data set's (dsData) table SubEntity with the data from the above select quer
           daSubEntity.Fill(dsData, "SubEntity"

           'set the data adapter to nothing, it is no longer needed after data set table has been fille
           daSubEntity = Nothin

           'determine if a subentity was found (no row in subentity). If no subentity was found then delete the table subentity and go to the function that will display the address based on the selected entity
           If (dsData.Tables("SubEntity").Rows.Count < 1) The
               'remove the subentity table since there are no records foun
               dsData.Tables.Remove("SubEntity"
               'hide the subentity selection screen (if visible
               lblSubEntities.Visible = Fals
               lstSubEntity.Visible = Fals
               btnSortAlphaAscSE.Visible = Fals
               btnSortAlphaDescSE.Visible = Fals
               grpSubEntity.Visible = Fals
               lblStep2.Visible = Fals
               lblStep3.Visible = Fals
               lblStep4.Visible = Fals
               lblStep5.Visible = Fals
               lblStep6.Visible = Fals
               lblStep7.Visible = Fals
               lblMailAddress.Visible = Fals
               lblPhysicalAddress.Visible = Fals
               lstAddress.Visible = Fals
               cboDeptStrategy.Visible = Fals
               cboDivisionStrategy.Visible = Fals
               cboType.Visible = Fals
               chkWolfYes.Visible = Fals
               chkWolfNo.Visible = Fals
               txtProjectDesc.Visible = Fals
               txtProjectDesc.Text = "

               'since there is no subentity show the addresses for the selected entity(go to function DisplayAddress, case Entit
               DisplayAddress("Entity"
               Exit Su
           End I

           'display the subentity selection scree
           lblSubEntities.Visible = Tru
           lstSubEntity.Visible = Tru
           btnSortAlphaAscSE.Visible = Tru
           btnSortAlphaDescSE.Visible = Tru
           grpSubEntity.Visible = Tru

           'set the data source to the data set's table SubEntit
           lstSubEntity.DataSource = dsData.Tables("SubEntity") <== this is where I receive erro

           'display the columns subentity nam
           lstSubEntity.DisplayMember = ("EntityName")  <== this is where I receive erro

           'set the value member to the subentity id for later referenc
           lstSubEntity.ValueMember = "SubEntityID

       Catch eException As Exceptio
           MsgBox("Error: " & eException.Message & " " & eException.Source
       End Tr
   End Su

Like I said, the code works even with the error messages. Any help in resolving this issue would be greatly appreciated
Looney Tunezez - 01 May 2004 00:31 GMT
Wel
Try thi
1stSubEntity.DataSource=dsData.Tables["SubEntity"]
Maybe this will hel
L
   
    ----- JR wrote: ----
   
    I am attempting to display two list boxes. In the first list box is a listing of all entities. When a entity is selected and it has a subentity the second list box displays with a list of the subentities. The code works but I get an error at the following two steps: (Code is VB.Net on a form
   
    'set the data source to the data set's table SubEntit
                lstSubEntity.DataSource = dsData.Tables("SubEntity"
   
    'display the columns subentity nam
                lstSubEntity.DisplayMember = ("EntityName"
   
    The error I receive is: Cast from type 'DataRowView' to type 'String' is not valid
   
    Here is the entire code
    Private Sub lstEntity_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntity.SelectedIndexChange
   
                           'define a new data adapte
                Dim daSubEntity As SqlClient.SqlDataAdapte
   
                'using the new data adapter attempt to locate in the database table tblSubEntity a subentity for the selected entity
                daSubEntity = New SqlClient.SqlDataAdapter("SELECT * FROM tblSubEntity WHERE Status = 1  AND CustomerID = " & lstEntity.SelectedValue & " ORDER BY EntityName", conn
   
                'fill the data set's (dsData) table SubEntity with the data from the above select quer
                daSubEntity.Fill(dsData, "SubEntity"
   
                'set the data adapter to nothing, it is no longer needed after data set table has been fille
                daSubEntity = Nothin
   
                'determine if a subentity was found (no row in subentity). If no subentity was found then delete the table subentity and go to the function that will display the address based on the selected entity
                If (dsData.Tables("SubEntity").Rows.Count < 1) The
                    'remove the subentity table since there are no records foun
                    dsData.Tables.Remove("SubEntity"
                    'hide the subentity selection screen (if visible
                    lblSubEntities.Visible = Fals
                    lstSubEntity.Visible = Fals
                    btnSortAlphaAscSE.Visible = Fals
                    btnSortAlphaDescSE.Visible = Fals
                    grpSubEntity.Visible = Fals
                    lblStep2.Visible = Fals
                    lblStep3.Visible = Fals
                    lblStep4.Visible = Fals
                    lblStep5.Visible = Fals
                    lblStep6.Visible = Fals
                    lblStep7.Visible = Fals
                    lblMailAddress.Visible = Fals
                    lblPhysicalAddress.Visible = Fals
                    lstAddress.Visible = Fals
                    cboDeptStrategy.Visible = Fals
                    cboDivisionStrategy.Visible = Fals
                    cboType.Visible = Fals
                    chkWolfYes.Visible = Fals
                    chkWolfNo.Visible = Fals
                    txtProjectDesc.Visible = Fals
                    txtProjectDesc.Text = "
   
                    'since there is no subentity show the addresses for the selected entity(go to function DisplayAddress, case Entit
                    DisplayAddress("Entity"
                    Exit Su
                End I
   
                'display the subentity selection scree
                lblSubEntities.Visible = Tru
                lstSubEntity.Visible = Tru
                btnSortAlphaAscSE.Visible = Tru
                btnSortAlphaDescSE.Visible = Tru
                grpSubEntity.Visible = Tru
   
                'set the data source to the data set's table SubEntit
                lstSubEntity.DataSource = dsData.Tables("SubEntity") <== this is where I receive erro
   
                'display the columns subentity nam
                lstSubEntity.DisplayMember = ("EntityName")  <== this is where I receive erro
   
                'set the value member to the subentity id for later reference
                lstSubEntity.ValueMember = "SubEntityID"
   
            Catch eException As Exception
                MsgBox("Error: " & eException.Message & " " & eException.Source)
            End Try
        End Sub
   
    Like I said, the code works even with the error messages. Any help in resolving this issue would be greatly appreciated.
    Thanks, JR

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.