Solved

I'm getting Data.DataRowView as my SelectedItem value from a listbox.  How do I get the actual value?

Posted on 2009-06-29
3
263 Views
Last Modified: 2012-06-21
I've got a listbox being populated with unique values from a table.  I'd like to be able to select one and use it as part of a filepath that links to another table (dervied from the original table based on the unique values...TiimeID).  The listbox shows up the unique values for TimeID, but when I try to select it and use a msgbox to check the new filepath, the filepath has "System.Data.DataRowView" instead of the value selected in the table.  Any suggestions??? Thanks!


Private Sub btnCreateDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateDB.Click
 
        DBProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
        'DBSource = "Data Source = C:/GEMSS/Apps/Kentucky Lake/Output/avg_highflow.mdb"
        DBSource = "Data Source = " & TextBox3.Text
        DBPath = TextBox3.Text
        Scenario = TextBox1.Text
        FileLoc = TextBox2.Text
 
        'MsgBox(DBSource)
        'Private MainConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath
        'con.ConnectionString = DBProvider & DBSource
        MainConnectionString = DBProvider & DBSource
        'MsgBox(MainConnectionString)
 
        'Private NewDBPath As String = "C:\GEMSS\Apps\Kentucky Lake\Output\avg_highflow_new_TimeID{0}.mdb"
        NewDBSource = FileLoc & "\" & Scenario & "_new_TimeID{0}.mdb"
        Dim NewDBPath As String = FileLoc & "\" & Scenario & "_new_TimeID{0}.mdb"
        'MsgBox(NewDBSource)
        'MsgBox(NewDBPath)
 
        NewDBConnectionStringTemplate = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}"
        'Private NewDBConnectionStringTemplate As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}"
 
        Dim conn As New OleDbConnection(MainConnectionString)
        Dim comm As OleDb.OleDbCommand = conn.CreateCommand()
        comm.CommandText = "SELECT DISTINCT TimeID FROM tblSurface"
        comm.CommandType = CommandType.Text
 
 
        dtTimeIDs = New DataTable()
        'conn.ConnectionString = MainConnectionString
        conn.Open()
        'MsgBox("You are using " & DBPath & "as the current database.")
        dtTimeIDs.Load(comm.ExecuteReader())
        conn.Close()
        'MsgBox("Database is now closed.")
 
 
        Me.lbTimeIDs.DataSource = dtTimeIDs
        Me.lbTimeIDs.DisplayMember = "TimeID"
        Me.lbTimeIDs.ValueMember = timeselect
 
 
        'Creates individual tables for each time step.
        Dim InsertQryStr As String = "INSERT INTO {0} SELECT * FROM tblSurface WHERE TimeID={1}"
        Dim thisDBPath As String
        Dim con2 As New OleDbConnection
        Dim com2 As OleDbCommand
 
        For i As Integer = 0 To Me.dtTimeIDs.Rows.Count
            If i > 11 Then
                Exit For
            Else
                thisDBPath = String.Format(NewDBPath, Me.dtTimeIDs.Rows(i)(0).ToString())
                'thisDBPath = NewDBPath & ",Me.dtTimeIDs.Rows(i) (0).ToString()"
                'MsgBox("ThisDBPath = " & thisDBPath)
                'MsgBox("DBPath = " & DBPath)
                'Me.lbTimeIDs.DisplayMember = DBPath
                System.IO.File.Copy(DBPath, thisDBPath)
 
                con2.ConnectionString = String.Format(NewDBConnectionStringTemplate, thisDBPath)
                com2 = con2.CreateCommand()
                com2.CommandText = "DELETE FROM tblSurface WHERE TimeID<>" + Me.dtTimeIDs.Rows(i)(0).ToString()
                com2.CommandType = CommandType.Text
                con2.Open()
                com2.ExecuteNonQuery()
                con2.Close()
 
            End If
        Next
    End Sub
 
Private Sub AddTbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddTbl.Click
        'Get a table based on the time selected in the list box and add it to ArcMap
        Dim FileLoc As String
        Dim Scenario As String
        Dim tblpth As String
        Dim timeselect As String = lbTimeIDs.SelectedItem.ToString()
 
        'Dim timeselect As String = lbTimeIDs.Items(lbTimeIDs.SelectedIndex).ToString()
        MsgBox("Seleccted time is " & timeselect)
        'Dim timeselect As String = lbTimeIDs.SelectedItem
        'From Experts-Exchange
        'timeselect = Me.lbTimeIDs.SelectedItem[{0}].ToString();
 
        Scenario = TextBox1.Text
        FileLoc = TextBox2.Text
        tblpth = FileLoc & "\" & Scenario & "_new_TimeID" & timeselect & ".mdb"
        MsgBox(tblpth)
 
'There's more after this, but the tblpath is wrong right now.
End Sub

Open in new window

0
Comment
Question by:jvs7829
[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
3 Comments
 
LVL 12

Expert Comment

by:ErezMor
ID: 24738772
there are a few ways ti get to it
this example will concatenate all values selected in a multi select listbox into a string
i believe you can derive what you want from it

For Each itm As Object In lstItems.SelectedItems
       str1 = str1 & ", " & lstItems.GetItemText(itm)
Next
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 24738940
The .SelectedItem returns the full object being bound, which is the DataRowView.

Use .SelectedValue instead, that will return the value from the datarow specified with
Me.lbTimeIDs.ValueMember
0
 

Accepted Solution

by:
jvs7829 earned 0 total points
ID: 24740600
Thanks for the assistance...I actually got an answer from an ESRI Forum person.

This worked:  
Dim timeselect As String = lbTimeIDs.SelectedItem(0).ToString()
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 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