Solved

Calling functions from a combobox SelectedIndexChanged

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now