Solved

Calling functions from a combobox SelectedIndexChanged

Posted on 2006-07-21
5
349 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 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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