none
how to refresh form or database RRS feed

  • Question

  • Dear All

    i have a form use for New Stock Item.

    now in that form i put a textbox which is coded as autocomplete. i call that textbox " category"

    if category not available in autocomplete then user can add new category by click the very next button and new form will open to add category

    now i have an issue that when user add new category, it not showing in autocomplete droplist unless user close the form and reopen it... is there any way where it automatically get listed after adding to category form as new .


    Wednesday, October 23, 2019 12:00 PM

All replies

  • Hello,

    Here is an example on a single form, when using a second form using ShowDialog and the secondary form sets DialogResult check if ShowDialog comes back with DialogResult.OK then simple add new item.

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            NamesTextBox.AutoCompleteMode = AutoCompleteMode.Suggest
            NamesTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
    
            Dim names = New AutoCompleteStringCollection
            names.Add("Mike")
            names.Add("Michelle")
            names.Add("Monica")
    
            NamesTextBox.AutoCompleteCustomSource = names
    
        End Sub
    
        Private Sub AddNameButton_Click(sender As Object, e As EventArgs) _
            Handles AddNameButton.Click
    
            NamesTextBox.AutoCompleteCustomSource.Add("Mary")
    
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, October 23, 2019 1:25 PM
    Moderator
  • Hi,

    Is this effect that you want?

    If so, you can try my code as follows, hope it be helpful.

    Module module1
        Public MySource As New AutoCompleteStringCollection()
    End Module
    
    Public Class Form1
        Private Sub NextStep_Click(sender As Object, e As EventArgs) Handles NextStep.Click
            Form2.Show()
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ' Create the list to use as the custom source.
            MySource.AddRange(New String() _
                                {
                                    "January",
                                    "February",
                                    "March",
                                    "April",
                                    "May",
                                    "June",
                                    "July"
                                })
            ' Initialize the text box.
            With Category
                .AutoCompleteCustomSource = MySource
                .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                .AutoCompleteSource = AutoCompleteSource.CustomSource
            End With
        End Sub
    End Class
    

    Public Class Form2
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            NewCategory.Text = Form1.Category.Text
        End Sub
    
        Private Sub Confirm_Click(sender As Object, e As EventArgs) Handles Confirm.Click
            MySource.AddRange(New String() {NewCategory.Text})
            MsgBox("Create successfully!")
            Me.Close()
        End Sub
    End Class

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 24, 2019 6:43 AM
    Moderator
  • actually let me show you in image example with code 

    im using below code for form 2 ( to add new brand) 

     Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
            Try
                conn = New SqlConnection(appx.myconnection)
                conn.Open()
                Dim cb As String = "insert into newbrand(brandid,brandname,username) Values (@d12,@d13,@d14)"
                cmd = New SqlCommand(cb)
                cmd.Parameters.AddWithValue("@d12", BrandidTextEdit.Text)
                cmd.Parameters.AddWithValue("@d13", BrandnameTextEdit.Text)
                cmd.Parameters.AddWithValue("@d14", UsernameTextEdit.Text)
                cmd.Connection = conn
                cmd.ExecuteReader()
                conn.Close()
                MsgBox(" Brand Name Addedd Successfully", vbOKOnly + vbInformation, "Brand Updated Successfully")
                updatebrand()
                BrandidTextEdit.Text = ""
                BrandnameTextEdit.Text = ""
                UsernameTextEdit.Text = ""
    
            Catch ex As Exception
                MsgBox(ex.Message, vbOKOnly + vbCritical, "Error-Brd-001")
            End Try
        End Sub

    and on main form 1 im using below code 

            BrandTextEdit.MaskBox.AutoCompleteSource = AutoCompleteSource.CustomSource
            BrandTextEdit.MaskBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend
            Dim brandcollector As New AutoCompleteStringCollection()
            brandnameauto(brandcollector)
            BrandTextEdit.MaskBox.AutoCompleteCustomSource = brandcollector
    
            Call connection()

    u can check below image as well 

    Thursday, October 24, 2019 12:53 PM
  • Hi,

    Please see my code as follows.

    Imports System.Data.SqlClient
    
    Module module1
        Public MySource As New AutoCompleteStringCollection()
        Public constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= D:\Local Database\Brand.mdf"
        Public conn As SqlConnection
        Public sda As SqlDataAdapter
        Public cmd As SqlCommand
        Public dt As New DataTable
        Public dr As SqlDataReader
    End Module
    
    Public Class Form1
        Private Sub NextStep_Click(sender As Object, e As EventArgs) Handles NextStep.Click
            Form2.Show()
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn = New SqlConnection(constr)
                conn.Open()
                cmd = New SqlCommand("select brandname from Brand", conn)
                dr = cmd.ExecuteReader()
                While dr.Read()
                    MySource.AddRange(New String() {dr("brandname").ToString()})
                End While
            End Using
    
            With Category
                .AutoCompleteCustomSource = MySource
                .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                .AutoCompleteSource = AutoCompleteSource.CustomSource
            End With
        End Sub
    End Class


    Imports System.ComponentModel
    Imports System.Data.SqlClient
    
    Public Class Form2
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From Brand", conn)
                dt.Clear()
                sda.Fill(dt)
                dgv.DataSource = dt
                dgv.EditMode = DataGridViewEditMode.EditOnEnter
                dgv.Columns(0).[ReadOnly] = True
    
    
                cmd = New SqlCommand("Select max(brandid) from brand", conn)
                Dim brandid, rightstr, leftstr As String
                brandid = ((cmd.ExecuteScalar().ToString).Trim())
                rightstr = ((CInt(brandid.Substring(brandid.Length - 3)) + 1).ToString()).PadLeft(3, "0")
                leftstr = brandid.Substring(0, brandid.Length - 3)
                BrandIdTb.Text = leftstr & rightstr
    
            End Using
        End Sub
    
        Private Sub Confirm_Click(sender As Object, e As EventArgs) Handles Confirm.Click
            Using conn = New SqlConnection(constr)
                conn.Open()
                cmd.Connection = conn
                cmd = New SqlCommand("insert into student values('{0}','{1}','{2}','{3}','{4}','{5}')", conn)
                cmd.CommandText = "insert into Brand(brandid,brandname) values(@brandid, @brandname)"
                cmd.Parameters.AddWithValue("brandid", BrandIdTb.Text)
                cmd.Parameters.AddWithValue("brandname", BrandNameTb.Text)
                cmd.ExecuteNonQuery()
    
                sda = New SqlDataAdapter("Select * From Brand", conn)
                dt.Clear()
                sda.Fill(dt)
                dgv.DataSource = dt
                dgv.EditMode = DataGridViewEditMode.EditOnEnter
                dgv.Columns(0).[ReadOnly] = True
            End Using
            MsgBox("Create successfully!")
            MySource.AddRange(New String() {BrandNameTb.Text})
        End Sub
    
        Private Sub Form2_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
            Using conn = New SqlConnection(constr)
                conn.Open()
                cmd = New SqlCommand("select brandname from Brand", conn)
                dr = cmd.ExecuteReader()
                While dr.Read()
                    MySource.AddRange(New String() {dr("brandname").ToString()})
                End While
            End Using
        End Sub
    End Class

    Hope it be helpful.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 25, 2019 7:01 AM
    Moderator