Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling functions from a combobox SelectedIndexChanged

Posted on 2006-07-21
5
Medium Priority
?
356 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
  • 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 750 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

Industry Leaders: 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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

916 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