Results 1 to 6 of 6

Thread: Refresh textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question Refresh textbox

    I need help on refreshing a textbox. I have updated the database with a SQL query and re-run the routine for creating the textbox and querying the information back to the textbox.text and on debug mode, it showed that the querying data are the most recent. However, when it is actually display on the form, the data hasn't refresh or updated. If I close the form and clear the panel and come back again then the textbox is refreshed and show the most recent changes.

    Many thanks in advance!

    Chong

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try txtBox.Refresh()
    Dont gain the world and lose your soul

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Are you using some kind of databinding to the textbox? be more precise in defining the situation please.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question

    Yes. I think I bind the textbox to the panel. If I clear the panel and re-run the routine to add the textbox back to the panel and run the query to populate the textbox with the result, then the textbox will show the most recent changes. The problem is I have multiple textboxes in that panel and I just want to refresh only one textbox, let's say textbox1. If I clear the panel items, all the textboxes in that panel will be gone.

    Chong

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I mean databinding, that is you bind the text property of the textbox to dataset.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question

    I don't think so then.

    Here's the code:
    Public Sub ScholarshipLoad()
    'Dim txtResult As New TextBox()
    Dim strSelected As String = lstApplicant.Items(lstApplicant.SelectedIndex).ToString()
    Dim plcHolder, strStanding, strSndStanding As String
    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbPath
    Dim strSQL As String = "SELECT * FROM Scholarship WHERE Scholarship.Scholarship=" & "'" & strSelected & "'"
    Dim shlDataAdapter As New OleDbDataAdapter(strSQL, strConn)
    shlDataAdapter.TableMappings.Add("Table", "Scholarship")
    Dim schlDataSet As New DataSet()
    shlDataAdapter.Fill(schlDataSet)
    Dim schlRow As DataRow
    Dim intScholarAmount As Integer
    Dim tblScholar As DataTable = schlDataSet.Tables(0)
    For Each schlRow In tblScholar.Rows
    strStanding = schlRow("Standing")
    strSndStanding = schlRow("sndstanding")
    If strStanding = "N" Then
    strStanding = "Not Require"
    End If
    If strSndStanding = "N" Then
    strSndStanding = "Not Require"
    ElseIf strSndStanding = "Above" Then
    strSndStanding = "Senior"
    End If
    If IsDBNull(schlRow("AmntAwarded")) = False Then
    intScholarshipAmount = CInt(schlRow("AmntAwarded"))
    intScholarAmount = CInt(schlRow("Amount")) - CInt(schlRow("AmntAwarded"))
    Else
    intScholarAmount = schlRow("Amount")
    End If
    plcHolder = "Require GPA: " & schlRow("GPA") & vbCrLf & "Require Major: " & schlRow("Major") & vbCrLf & "Must be: " & _
    strStanding & " to: " & strSndStanding & vbCrLf & "Total Amount: $" & intScholarAmount

    Next schlRow
    mtplResult(plcHolder)

    End Sub

    Public Sub mtplResult(ByRef plcHolder As String)
    Dim txtResult As New TextBox()
    Dim txtAward As New TextBox()
    Dim lblAmount As New Label()
    Dim strTextBoxInc As String
    Dim strTextBoxResult As String

    x = 8
    n += 1

    If blnSchlTF = True And blnQlfy = False Then
    h = 60 'from 50 to 60
    x = 8
    y = 8
    strTextBoxResult = "txtBoxScholarship"
    ElseIf blnSchlTF = True And blnQlfy = True Then
    If h = 60 AndAlso y = 8 Then
    h = 165
    x = 8
    y = 90 'from 80 to 90
    Else
    y += 175
    End If
    strTextBoxResult = "txtQualifiedApplicant"
    End If
    pnlAppResult.SuspendLayout()
    With txtResult
    .Name = strTextBoxResult
    .Width = 264
    .Height = h
    .AllowDrop = True
    .Location = New Point(x, y)
    .AutoSize = True
    .Multiline = True
    .ScrollBars = ScrollBars.Vertical
    .Text = plcHolder
    .BackColor = System.Drawing.Color.White
    .ReadOnly = True
    .Visible = True
    .Show()
    End With
    AddHandler txtResult.DragEnter, AddressOf txtResult_DragEnter
    AddHandler txtResult.DragDrop, AddressOf txtResult_DragDrop
    pnlAppResult.Controls.Add(txtResult)
    pnlAppResult.ResumeLayout(True)

    End Sub
    And here is the routine for updating and calling the ScholarshipLoad() to re-display the textbox.name = "txtBoxScholarship" again and refresh this textbox.

    Private Sub txtResult_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtResult.DragDrop
    popAmount()
    Dim strHolder As String
    Dim strName As String
    Dim strSSNsubstring As String
    Dim strSeperator As String
    Dim tb As TextBox = CType(sender, TextBox)
    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbPath
    Dim strSQL, strSQLInsert As String
    Dim rdr As OleDbDataReader
    Dim cn As New OleDbConnection(strConn)
    Dim cmd As OleDbCommand = cn.CreateCommand()
    Dim intAmountLeft As Integer
    Dim strSelected As String = lstApplicant.Items(lstApplicant.SelectedIndex).ToString()

    strName = tb.Text()
    strSSNsubstring = strName.Substring(5, 9)
    intSSNnumb = CInt(strSSNsubstring)
    strSeperator = "***************************"

    'strHolder = e.Data.GetData(lstApplicant.Text().GetType.ToString())
    strHolder = lstApplicant.Items(lstApplicant.SelectedIndex).ToString()

    tb.Text = strName & vbCrLf & strSeperator & vbCrLf & "Awarded: " & strHolder & " scholarship" & _
    vbCrLf & "SSN#: " & intSSNnumb & vbCrLf & "Amount Award: $" & strAmount
    cn.Open()
    strSQL = "SELECT COUNT(*) FROM Awarded WHERE awrdID=" & intSSNnumb
    Dim cmdSQL As New OleDbCommand(strSQL, cn)

    Try
    Dim count As Integer = cmdSQL.ExecuteScalar
    If count > 0 Then
    'records found so update
    cmd.CommandText = "UPDATE Awarded SET awrdName=" & "'" & strHolder & "'" & " awrdAmount =" & strAmount & " WHERE awrdID=" & intSSNnumb
    cmd.ExecuteNonQuery()
    Else
    'records not found so add to database
    strSQLInsert = "INSERT INTO Awarded (awrdID, awrdName, awrdAmount) VALUES(" & intSSNnumb & ", '" & strHolder & "', '" & strAmount & "')"
    Dim cmdQuery As New OleDbCommand(strSQLInsert, cn)
    cmdQuery.ExecuteNonQuery()
    End If
    intAmountLeft = intScholarshipAmount + CInt(strAmount)
    'intAmountLeft = CInt(strAmount)
    If intAmountLeft > 0 Then
    cmd.CommandText = "UPDATE Scholarship SET AmntAwarded=" & intAmountLeft & " WHERE Scholarship LIKE " & "'" & strSelected & "'"
    cmd.ExecuteNonQuery()
    'blnSchlTF = True
    blnQlfy = False
    'txtResult.Clear()
    ScholarshipLoad()
    blnQlfy = True
    End If
    Catch dbException As Exception
    MessageBox.Show(dbException.Message)
    End Try
    cn.Close()
    End Sub
    Thanks for trying to help!

    Chong

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width