Click here to Skip to main content
15,911,481 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to Set different forecolor to numbers between 0-9. Pin
mdrizwan_14-Jun-10 21:13
mdrizwan_14-Jun-10 21:13 
GeneralRe: How to Set different forecolor to numbers between 0-9. Pin
Dave Kreskowiak5-Jun-10 2:10
mveDave Kreskowiak5-Jun-10 2:10 
GeneralRe: How to Set different forecolor to numbers between 0-9. Pin
mdrizwan_15-Jun-10 2:20
mdrizwan_15-Jun-10 2:20 
QuestionHow To Sort DataGridView Pin
Thaer Hamael2-Jun-10 19:55
Thaer Hamael2-Jun-10 19:55 
AnswerRe: How To Sort DataGridView Pin
Chris C-B2-Jun-10 20:13
Chris C-B2-Jun-10 20:13 
AnswerRe: How To Sort DataGridView Pin
Abhinav S2-Jun-10 20:19
Abhinav S2-Jun-10 20:19 
AnswerRe: How To Sort DataGridView Pin
Baconbutty2-Jun-10 21:29
Baconbutty2-Jun-10 21:29 
QuestionLost_focus and save button. Pin
lemarshall2-Jun-10 16:51
lemarshall2-Jun-10 16:51 
I have a total of 65 text boxes which the user can fill in. They are 13 down and 5 across. Each row is related to a particular material (which can change daily -see earlier posts) the columns are for quality of material.

In Debug mode stepping through the code this is what happens:
If I pull up the form and enter data into one textbox and then click on the save button the program goes through the save routine, but there is nothing to save and then it hits the Lost_focus event of the text box and runs through and saves the data to the collection class but doesn't save the information.

If I enter one text box and then tab to another the Lost_focus of the first textbox saves the data to the collection class and then click on the Save button the program saves the info to the tables properly and then runs the Lost_focus event of the second text box.

I don't remember this happening in VB6 so I am sure it has to do with the new form collection class, etc. I am confused and wonder now what is the proper way to proceed. I need to be able to save for each form anywhere from 1 to 65 types of material on each form.

The text_changed proeprty won't work as it fires on each digit being entered- 123 causes the event to fire 3 times.

Here is the code for the SaveMaterial function from the save button, the StoreMaterial2COL function and the first couple of lost_focus Subs:
Private Function SaveMaterial() As Boolean

    Try
        ' The index of a zero-based collection is Count property minus 1.
        Dim iCnt As Integer
        iCnt = myMaterialsCollection.Count
        iCnt = iCnt - 1

        With myMaterialsCollection
            For Each aItem In myMaterialsCollection
                If iCnt = -1 Then
                    Exit For
                End If
                _gblString = CreateGUIDString()

                gblConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\JWI\Data\JWI.mdb;Jet OLEDB:Database Password=jWi;")

                strData = "INSERT INTO LOLItems (LOLItemsID, LOLIFormID, Type, TextBox, MaterialsID, Units, DateCreated )" _
                & " VALUES ('" & _gblString & "',  " _
                & "'" & _frmGuid & "', '" _
                & 1 & "',' " _
                & aItem.txtBoxName & "',' " _
                & aItem.MaterialID & "',' " _
                & aItem.jnts & "',' " _
                & Now() & "');"

                gblCMD.Connection = gblConn
                gblCMD.CommandText = strData
                Dim cmd As New System.Data.SqlClient.SqlCommand

                gblConn.Open()
                gblCMD.ExecuteNonQuery()

                myMaterialsCollection.Remove(iCnt)
                iCnt = iCnt - 1  'decrement until empty
            Next

        End With

    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Function

Public Function StoreMaterial2COL(ByRef matID As String, ByRef ctrlname As String, ByRef jnts As String)
    Try
        'need to check to make sure the txtboxName has not been entered already
        'if so then the user is updated the amt and we need to update the
        'jnts and not add a new record.
        aItem.txtBoxName = ctrlname
        aItem.MaterialID = matID
        aItem.jnts = jnts

        myMaterialsCollection.Add(aItem)
    Catch ex As Exception

        'Catch ex As System.InvalidCastException
        MsgBox(ex.ToString)
    End Try
    Return True

End Function

'*#*#*#*#*#*#*#*#*#*#*#*#*
'Need to try to make a more generic method of doing this- a control array maybe????
'This is for column 1 Junk Rods
Private Sub txtRodJ_0_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRodJ_0.LostFocus
    StoreMaterial2COL(lblRods_0.Tag, txtRodJ_0.Name, txtRodJ_0.Text)
End Sub
Private Sub txtRodJ_1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRodJ_1.LostFocus
    StoreMaterial2COL(lblRods_1.Tag, txtRodJ_1.Name, txtRodJ_1.Text)
End Sub
Private Sub lblRodJ_2_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRodJ_2.LostFocus
    StoreMaterial2COL(lblRods_2.Tag, txtRodJ_2.Name, txtRodJ_2.Text)
End Sub
Private Sub txtRodJ_3_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRodJ_3.LostFocus
    StoreMaterial2COL(lblRods_3.Tag, txtRodJ_3.Name, txtRodJ_3.Text)
End Sub


As always any assistance is greatly welcomed.
Larry
AnswerRe: Lost_focus and save button. Pin
Dr.Walt Fair, PE2-Jun-10 17:15
professionalDr.Walt Fair, PE2-Jun-10 17:15 
GeneralRe: Lost_focus and save button. Pin
lemarshall2-Jun-10 17:32
lemarshall2-Jun-10 17:32 
AnswerRe: Lost_focus and save button. Pin
George B Gilbert2-Jun-10 17:17
George B Gilbert2-Jun-10 17:17 
GeneralRe: Lost_focus and save button. Pin
lemarshall2-Jun-10 17:32
lemarshall2-Jun-10 17:32 
GeneralRe: Lost_focus and save button. Pin
George B Gilbert2-Jun-10 19:03
George B Gilbert2-Jun-10 19:03 
GeneralRe: Lost_focus and save button. Pin
lemarshall3-Jun-10 2:40
lemarshall3-Jun-10 2:40 
GeneralRe: Lost_focus and save button. Pin
George B Gilbert3-Jun-10 6:35
George B Gilbert3-Jun-10 6:35 
GeneralRe: Lost_focus and save button. Pin
lemarshall3-Jun-10 16:13
lemarshall3-Jun-10 16:13 
AnswerRe: Lost_focus and save button. Pin
Henry Minute3-Jun-10 4:22
Henry Minute3-Jun-10 4:22 
QuestionGenerating Error While Set the FontStyle Pin
Anubhava Dimri1-Jun-10 20:43
Anubhava Dimri1-Jun-10 20:43 
AnswerRe: Generating Error While Set the FontStyle Pin
Wayne Gaylard1-Jun-10 21:46
professionalWayne Gaylard1-Jun-10 21:46 
GeneralRe: Generating Error While Set the FontStyle Pin
Anubhava Dimri2-Jun-10 0:45
Anubhava Dimri2-Jun-10 0:45 
AnswerRe: Generating Error While Set the FontStyle Pin
walterhevedeich2-Jun-10 0:35
professionalwalterhevedeich2-Jun-10 0:35 
QuestionHow I search DataGridView with text column? Pin
Curious 20091-Jun-10 10:35
Curious 20091-Jun-10 10:35 
AnswerRe: How I search DataGridView with text column? Pin
Luc Pattyn1-Jun-10 10:48
sitebuilderLuc Pattyn1-Jun-10 10:48 
GeneralRe: How I search DataGridView with text column? Pin
Curious 20091-Jun-10 11:07
Curious 20091-Jun-10 11:07 
GeneralRe: How I search DataGridView with text column? Pin
Luc Pattyn1-Jun-10 11:17
sitebuilderLuc Pattyn1-Jun-10 11:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.