Solved

Calling functions from a combobox SelectedIndexChanged

Posted on 2006-07-21
5
353 Views
Last Modified: 2012-08-13
Currently I have a series of functions being called from a Button_Click event to refresh the  form and using the selected material item in my combobox.

Ideally, I'd like the same set of functions and text box fills when the user selects a different material item with the combobox rather than forcing the button click every time new item is selected.

I tried adding the function call GetOnHand() to my SelectedIndexChanged but I get this error:


Cast from type 'DataRowView' to type 'String' is not valid



The functions is called

GetOnHand()



Public Function GetOnHand() As Double

Try
sql string
new odbc command
cmd.ExecuteScalar
End Try
Return value
End Function


Thanks,
Jon
0
Comment
Question by:JMO9966
[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
  • 2
  • 2
5 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17155684
Jon,

If you want us to help with your code, you need to show the relevant code. Right now, more than 50% of what you posted will throw errors.

The most likely issue is that you've got a dataview that you're trying to retrieve data from, and instead of getting the data from the row using DataView(rowIndex)(fieldName), you've used DataView(rowIndex).

But this is just a wild guess, since we don't have your code to look at.

Chaosian
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17155892
try

Dim val as Double

val=GetOnHand()

0
 

Author Comment

by:JMO9966
ID: 17164966
Here's the function:

Public Function GetOnHand() As Double

        Try

            Dim sql As String = "select sum(On_Hand_Qty) from Material_Location where Material =" & "'" & cboMaterialID.SelectedValue & "'"


            Dim cmd As New Odbc.OdbcCommand(sql, dcMRP)
            dcMRP.Open()

            OnHandQty = cmd.ExecuteScalar


        Catch oex As OleDbException
            MessageBox.Show(oex.Message)
            Return 0
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return 0
        Finally
            If dcMRP.State = ConnectionState.Open Then dcMRP.Close()
        End Try
        Return OnHandQty


    End Function


I call it with a button click event and it works fine, I populate value into a text box:

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click


        GetOnHand()

        txtPastDue_OnHand.Text = OnHandQty.ToString




Trying to get it to also refresh On Hand for the item chosen with ComboBox:

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click

        GetOnHand()

0
 

Author Comment

by:JMO9966
ID: 17171232
Any thoughts guys?

Thanks,
Jon
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 250 total points
ID: 17171854
I still don't see where the error would be thrown -- your code looks fine. What line throws the error?
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

617 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