Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling functions from a combobox SelectedIndexChanged

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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