Hi,

I'm having a hair-rising casting problem.

The problem is the following: in a form there is a listbox in which the user can make different selections. The listbox has the following code (indicated in the load subroutine of the form):

Me.ListBox.DataSource = Me.DSlistboxes
Me.ListBox.DisplayMember = "tblMainGroup.MaingroupDescription"
Me.ListBox.ValueMember = "tblMainGroup.MaingroupID"

Where MainGroupID is an autonumber in the underlying access 2000 database.

Based on the selection of the user I want to display a corresponding code (SubGroupAbbreviation) in a textbox. Therefore I wrote the following code:

Private Sub ListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox3.SelectedIndexChanged
Dim SQLWeergaveCode As String

(*) SQLWeergaveCode = "SELECT * FROM tblMainGroup WHERE MainGroupID= " & Me.ListBox.SelectedValue
Me.DAWeergaveCode = New OleDbDataAdapter(SQLWeergaveCode, DataConnection)
'DataConnection.Open()
DAWeergaveCode.Fill(DSWeergaveCode, "tblSubgroup")
'DataConnection.Close()
Me.TextBoxCode.DataBindings.Clear()
Me.TextBoxCode.DataBindings.Add("text", DSWeergaveCode, "tblMainGroup.MainGroupAbbreviation")
End Sub

When I compile this code I get the following error:

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from type 'DataRowView' to type 'String' is not valid.

The error occurs at the line indicated with (*). I don't understand this error because I think that me.listbox.selectedvalue is an integer???

.

Or is there an easier way to accomplish what I want:
table with three fields:
MainGroupID (autonumber, pk)
MainGroupDescription
MainGroupAbbreviation

The MainGroupdescription must be shown in the listbox and when the user clicks on an item then the corresponding MainGroupAbbreviation must be shown in a textbox. When the user clicks another item, the text shown in the textbox must also change.


Thanks,

Tom