none
how to search and autofill datagrid using 1st column RRS feed

  • Question

  • dear all

    i have a invoice table

    now in that datagrid table i have 4 columns 

    itemcode        itemdescription      qty        price

    now what i need is 

    user come to itemcode and whenever he type itemcode, he should get a list of initial alphabetic itemnames like if i type A so itemcode must show all items codes related to A

    and when i get my required itemcode, after pressing enter it should fill the related field (item description,qty,price)

    please guide with codes

    thanks 

    Monday, April 8, 2019 12:33 PM

Answers

  • i solved this issue 

    now i have issue here 

      updateQuery = "UPDATE COA SET opening_balance = opening_balance + '" & TotalamountTextBox.Text & "'  WHERE AccountID = '" & Coa_idTextBox.Text & "'"

    instead of adding opening_balance with existing, it showing new value with old 

    example

    if i have opening balance of any account 500 and if i made any entry of 1000 then it must be 1500 but it showing me 5001000

    please help

    • Marked as answer by Omi4u Monday, May 27, 2019 11:25 AM
    Monday, May 6, 2019 8:02 AM

All replies

  • i am getting this error while entering data from textbox to datagrid.

    i have a method 

         

        Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown



            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn() With {.ColumnName = "hiddenid", .DataType = GetType(Integer),
                              .AutoIncrement = True, .AutoIncrementSeed = 1})

            dt.Columns("hiddenid").ColumnMapping = MappingType.Hidden



            dt.Columns.Add(New DataColumn() With {.ColumnName = "autonumber", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn() With {.ColumnName = "location", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn() With {.ColumnName = "date", .DataType = GetType(String)})





            bsData.DataSource = dt
            NDRDataGridView.DataSource = bsData
            ' Label3.DataBindings.Add("text", bsData, "stockin_id")








        End Sub

        Private Sub AutonumberTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles AutonumberTextBox1.KeyPress
            If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then

                If Not String.IsNullOrWhiteSpace(AutonumberTextBox.Text) Then
                    CType(bsData.DataSource, DataTable).Rows.Add(New Object() {Nothing, AutonumberTextBox1.Text, LocationTextBox.Text, DateTextBox1.Text})
                    bsData.MoveLast()
                End If

            End If

        End Sub

    but when i use above codes, it worked for me but it do not allow me to see relationship data.

    i need 

    i have two tables table1 =  t1
    table 2 =T1r

    both have relationship 

    i want when user fill textbox and press enter in last textbox, the data of all other textboxes get added in datagrid with autonumber (identity from sql)

    please help and guide me with codes 

    • Merged by Alex Li-MSFT Thursday, April 18, 2019 3:11 AM same case
    Monday, April 8, 2019 9:32 AM
  • Going with the title of this post, I see the following which clinically speaking looks fine.

    CType(bsData.DataSource, DataTable).Rows.Add(New Object() {Nothing, AutonumberTextBox1.Text, LocationTextBox.Text, DateTextBox1.Text})

    What is unclear, perhaps because there is a lack of details is the following statement as all you have shown is one table and you are asking about two or more tables when indicating a relationship. Usually a relationship is set in a DataSet to the relationship property between two tables by primary keys which there is no code shown for this.

    "but when i use above codes, it worked for me but it do not allow me to see relationship data."


    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

    Monday, April 8, 2019 9:54 AM
    Moderator
  • yeah i know ma'am and i mentioned above codes are working fine but when i use this code for 2 tables which have relationships. here i am not able to see the relationship of data.

    suppose i have a item related to numberID 1 so when i use above codes it show me only id 1 but not the related items. as soon i remove above codes, i get everything . i face issue with codes that i am using in form_shown 

    i need smile small code to do my job please 

    i want to add textdata to datagrid which is databind. whenever user fill the last textbox and press enter

    all data in textbox must transfer to datagrid 

    Monday, April 8, 2019 10:09 AM
  • I have code samples but are not small.

    The following example is broken down into a frontend and backend. Relationships are set in this class. Then in the following code sample, at the bottom there are links to two more out of three links.

    All of the code samples mentioned above share a common pattern which I wrote.


    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

    Monday, April 8, 2019 10:34 AM
    Moderator
  • i saw your example. only have issue to add textbox items to datagrid 

    for relationship i solved it with very best way 

    Monday, April 8, 2019 10:49 AM
  • i saw your example. only have issue to add textbox items to datagrid 

    for relationship i solved it with very best way 

    Unsure what you mean but all you have to do after reading my code is to simply add the data binding e.g. firstNameTextBox.DataBindings.Add("Text",MasterBindingSource, "FirstName") for example.

    What do you mean by "for relationship i solved it with very best way", for me and other that leaves us guessing which is not nice of you to say this.


    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

    Monday, April 8, 2019 10:55 AM
    Moderator
  • i will tell you and others with an example that how i solve the issue of relationship 

    but for now i need 

    i want to add textbox value to datagrid . 

    if possible can you pleaseeee write for me a code here that i can use instead of going through your example . please 

    Monday, April 8, 2019 11:05 AM
  • i will tell you and others with an example that how i solve the issue of relationship 

    but for now i need 

    i want to add textbox value to datagrid . 

    if possible can you pleaseeee write for me a code here that i can use instead of going through your example . please 

    Here is something I put together in about 15 minutes which is all the time I have. There are actually three tables relations where I do all three but show only two for time constraints.

    https://1drv.ms/u/s!AtGAgKKpqdWjjRtBbJLQRQ6bcVJY


    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

    Monday, April 8, 2019 11:48 AM
    Moderator
  • thank you for your sample but your example is showing me only to edit existing data

    see in attachment

    i need this , after user add details in textboxes, he\she will press the add to grid and textbox data will get added in datagrid 

    Monday, April 8, 2019 11:58 AM
  • thank you for your sample but your example is showing me only to edit existing data

    see in attachment

    i need this , after user add details in textboxes, he\she will press the add to grid and textbox data will get added in datagrid 

    You then need to call AddNew on the BindingSource to add the new row. using my last code sample to add a new row for products se bsProducts.AddNew() then after the user enters the data issue bsProducts.EndEdit then bsProducts.ResetBindings(False). For a new identifier the primary key needs to be auto incrementing e.g.

    dtParent.Columns.Add(
        New DataColumn With
        {
            .ColumnName = "Identifier",
            .DataType = GetType(Int32), 
            .AutoIncrement = True
        }
    )
    This is all I have time for as I'm heading to work so good luck.


    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

    Monday, April 8, 2019 12:21 PM
    Moderator
  • hi all

    i have datagrid with few details

    i need whenever user click on 1st row , it open form2 to add details and when user fill form2 and press and 

    the details of form2 must add in datagrid selected row.

    please guide with code 

    Monday, April 8, 2019 12:40 PM
  • Since this is really the same as your last post I'm merging them.

    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

    Monday, April 8, 2019 12:42 PM
    Moderator
  • Hello,

    So far today you asked three questions, two are pretty much the same. Here we like for you to ask a single question, get a solution then move to a new question. If you keep doing this I will take similar actions as i just did with merging two questions together.


    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

    Monday, April 8, 2019 12:46 PM
    Moderator
  • actually i am about to leave from office and i posted 3 questions so tomorrow when i will come i will able to work on the answers , this is why i post 3 different questions 
    Monday, April 8, 2019 12:52 PM
  • actually i am about to leave from office and i posted 3 questions so tomorrow when i will come i will able to work on the answers , this is why i post 3 different questions 
    Well two of them are now merged. Here is a thought for you, 99 percent of the time a developer focuses on one problem at a time rather than multiple problems which is what I recommend too. So again keep to one question at a time.

    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

    Monday, April 8, 2019 1:28 PM
    Moderator
  • ok ma'am but i am still waiting for answer of these questions 

    Tuesday, April 9, 2019 5:19 AM
  • any help please
    Tuesday, April 9, 2019 6:26 AM
  • Hi,
    here is a demo how to use data relation in DataSet and how add new rows to the the master and to the childs for selected master:

    Public Class Form14
    
      Private dgvMaster As New DataGridView With {.Top = 10, .Left = 10, .Height = 300, .Width = 400,
        .Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right,
        .AllowUserToAddRows = False}
      Private dgvChild As New DataGridView With {.Top = 320, .Left = 10, .Height = 300, .Width = 400,
        .Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right,
        .AllowUserToAddRows = False}
      Private bsMaster As New BindingSource
      Private bsChild As New BindingSource
      Private WithEvents tbMaster As New TextBox With {.Text = "<new Master>", .Top = 10, .Left = 420,
        .Anchor = AnchorStyles.Top Or AnchorStyles.Right}
      Private WithEvents tbChild As New TextBox With {.Text = "<new Child>", .Top = 320, .Left = 420,
        .Anchor = AnchorStyles.Top Or AnchorStyles.Right}
      Private ds As New DataSet
    
      Private Sub Form14_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Height = 700
        Me.Width = 700
        Me.Controls.AddRange(New Control() {dgvMaster, tbMaster, dgvChild, tbChild})
        GetData()
        bsMaster.DataSource = ds
        bsMaster.DataMember = "Master"
        dgvMaster.DataSource = bsMaster
        bsChild.DataSource = bsMaster
        bsChild.DataMember = "Rel"
        dgvChild.DataSource = bsChild
      End Sub
    
      Private Sub tbMaster_KeyDown(sender As Object, e As KeyEventArgs) Handles tbMaster.KeyDown
        If e.KeyCode = Keys.Enter Then
          ds.Tables("Master").Rows.Add(Nothing, CType(sender, TextBox).Text)
        End If
      End Sub
    
      Private Sub tbChild_KeyDown(sender As Object, e As KeyEventArgs) Handles tbChild.KeyDown
        If e.KeyCode = Keys.Enter Then
          CType(bsChild.AddNew, DataRowView).Row("ChildInfo") = CType(sender, TextBox).Text
        End If
      End Sub
    
      Private Sub GetData()
        ' simulate data loading
        Dim rnd As New Random
        ' Master
        Dim dtMaster As New DataTable("Master")
        With dtMaster
          With .Columns
            With .Add("ID", GetType(Integer))
              .AutoIncrement = True
              .AutoIncrementSeed = -1
              .AutoIncrementStep = -1
            End With
            .Add("MasterInfo", GetType(String))
          End With
          For i = 1 To 10
            .Rows.Add(Nothing, $"Master {i}")
          Next
        End With
        ' Child
        Dim dtChild As New DataTable("Child")
        With dtChild
          With .Columns
            With .Add("ID", GetType(Integer))
              .AutoIncrement = True
              .AutoIncrementSeed = -1
              .AutoIncrementStep = -1
            End With
            .Add("FK", GetType(Integer))
            .Add("ChildInfo", GetType(String))
          End With
          For i = 1 To 100
            .Rows.Add(Nothing, -rnd.Next(1, 11), $"Child {i}")
          Next
        End With
        ' Dataset and Relation
        With ds
          .Tables.Add(dtMaster)
          .Tables.Add(dtChild)
          .Relations.Add("Rel", dtMaster.Columns("ID"), dtChild.Columns("FK"))
        End With
      End Sub
    
    End Class


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Tuesday, April 9, 2019 7:16 AM
  • dear sir

    thank u you for your code but i need simple code to add textbox data in datagrid which is databound.

    Tuesday, April 9, 2019 7:50 AM
  • Hi,

    Do you want such an effect like this?

    Public Class Form1
        Dim dt As New DataTable
        Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection()
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            strings.Add("Abbbb")
            Strings.Add("Bbbbb")
            strings.Add("Cbbbb")
    
        End Sub
    
        Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
            If DataGridView1.CurrentCell.ColumnIndex.Equals(0) Then
                Dim txtAmount As TextBox = TryCast(e.Control, TextBox)
                txtAmount.AutoCompleteCustomSource = strings
                txtAmount.AutoCompleteSource = AutoCompleteSource.CustomSource
                txtAmount.AutoCompleteMode = AutoCompleteMode.Suggest
            End If
        End Sub
    
    End Class
    

    Best Regards,

    Alex


    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.

    Tuesday, April 9, 2019 8:05 AM
  • Hi,
    if you work in unbounded mode the values are stored in background in DataGridView. If you bind data objects (DataSource) the DataGrid get every time the values from bounded data object. If you want add or change the showed values you must change the values in the bounded data objects.

    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Tuesday, April 9, 2019 8:15 AM
  • dear alex bro thank you for your codes 

    but i need to fill the related fields as well when i get 1st column (itemcode)

    n i need for ms sql database .

    Tuesday, April 9, 2019 9:24 AM
  • Hi,

    If you have already obtained dt from the database:

    Public Class Form1
        Dim dt As New DataTable
        Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection()
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            dt.Columns.Add("itemcode")
            dt.Columns.Add(" itemdescription")
            dt.Columns.Add("qty")
            dt.Columns.Add("price")
            dt.Rows.Add(New Object() {"Abbbb", "a", 1, 15})
            dt.Rows.Add(New Object() {"Bbbbb", "b", 2, 15})
            dt.Rows.Add(New Object() {"Cbbbb", "c", 3, 15})
            For Each d In dt.Rows
                strings.Add(d(0).ToString)
            Next
    
        End Sub
    
        Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
            If DataGridView1.CurrentCell.ColumnIndex.Equals(0) Then
                Dim TextBox As TextBox = TryCast(e.Control, TextBox)
                TextBox.AutoCompleteCustomSource = strings
                TextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
                TextBox.AutoCompleteMode = AutoCompleteMode.Suggest
                AddHandler TextBox.TextChanged, AddressOf texte
    
            End If
        End Sub
    
    
        Private Sub texte(sender As Object, e As EventArgs)
            Dim TextBox As TextBox = TryCast(sender, TextBox)
            If strings.Contains(TextBox.Text) Then
                Dim a = strings.IndexOf(TextBox.Text)
                DataGridView1.Rows.Add()
                Me.DataGridView1.CurrentRow.Cells(1).Value = dt(a)(1)
                Me.DataGridView1.CurrentRow.Cells(2).Value = dt(a)(2)
                Me.DataGridView1.CurrentRow.Cells(3).Value = dt(a)(3)
            End If
        End Sub
    End Class
    

    Best Regards,

    Alex


    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.

    Tuesday, April 9, 2019 10:14 AM
  • great help but still can u pleaseeeeeee mention how i can use it with ms sql....im not that good with sql bro please 
    Tuesday, April 9, 2019 10:17 AM
  • i found the issue now i need to solve it with your help

    here is the code

      Public bsData As New BindingSource

       Dim dtr As New DataTable

           

            dtr.Columns.Add(New DataColumn() With {.ColumnName = "hiddenid", .DataType = GetType(Integer),
                             .AutoIncrement = False, .AutoIncrementSeed = False})
            dtr.Columns("hiddenid").ColumnMapping = MappingType.Hidden


            dtr.Columns.Add(New DataColumn() With {.ColumnName = "autonumber", .DataType = GetType(String)})
            dtr.Columns.Add(New DataColumn() With {.ColumnName = "location", .DataType = GetType(String)})
            dtr.Columns.Add(New DataColumn() With {.ColumnName = "date", .DataType = GetType(String)})
      1      bsData.DataSource = dtr
       2     NDRDataGridView.DataSource = bsData

       If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then

                If Not String.IsNullOrWhiteSpace(HiddenidTextBox.Text) Then
                    CType(bsData.DataSource, DataTable).Rows.Add(New Object() {Nothing, AutonumberTextBox1.Text, LocationTextBox.Text, DateTextBox1.Text})
                    bsData.MoveLast()
                End If

            End If

    this code work fine if i use it with one table ..... like if i use it with textbox and press enter then it will add values of textboxes to datagrid

    but when i use it with relationship tables , it hide data of FK table but if i remove LINE 1 AND LINE 2 (mentioned in codes)

    then i can able to see the FK data.

    now i need your help to replace similar code where LINE 1 AND LINE 2 get removed or replaced else code is working fine 

    Tuesday, April 9, 2019 11:06 AM
  • Hi,

    Do you want to get Datatable from ms sql,like  this?

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "xxx"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From Student", conn)
                dt = New DataTable()
                sda.Fill(dt)       
            End Using
        End Sub
    End Class

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/index

    Best Regards,

    Alex


    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.

    Wednesday, April 10, 2019 1:13 AM
  • yes i want to retrive data in datagrid as u did above but i want to use mssql database to do it. can u please join both above codes and make one for me so i can able to search records in datagrid 
    Wednesday, April 10, 2019 5:12 AM
  • waiting for reply
    Wednesday, April 10, 2019 5:12 AM
  • Hi,

    Is this okay?

    database invoice table

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection()
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With DataGridView1
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "itemcode"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "itemdescription"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "qty"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "price"})
            End With
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From invoice", conn)
                dt = New DataTable()
                sda.Fill(dt)
            End Using
            For Each d In dt.Rows
                strings.Add(d(0).ToString)
            Next
        End Sub
    
        Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
            If DataGridView1.CurrentCell.ColumnIndex.Equals(0) Then
                Dim TextBox As TextBox = TryCast(e.Control, TextBox)
                TextBox.AutoCompleteCustomSource = Strings
                TextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
                TextBox.AutoCompleteMode = AutoCompleteMode.Suggest
                AddHandler TextBox.TextChanged, AddressOf texte
    
            End If
        End Sub
        Private Sub texte(sender As Object, e As EventArgs)
            Dim TextBox As TextBox = TryCast(sender, TextBox)
            If Strings.Contains(TextBox.Text) Then
                Dim a = strings.IndexOf(TextBox.Text)
                Me.DataGridView1.CurrentRow.Cells(1).Value = dt(a)(1)
                Me.DataGridView1.CurrentRow.Cells(2).Value = dt(a)(2)
                Me.DataGridView1.CurrentRow.Cells(3).Value = dt(a)(3)
            End If
        End Sub
    End Class

    Best Regards,

    Alex


    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.

    Wednesday, April 10, 2019 5:33 AM
  • yes i need same but i tried your code and it not working

     

     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


           With NDRDataGridView
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "hiddenid"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "autonumber"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "location"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "date"})
            End With
            Using conn1 = New SqlConnection(constr)
                conn1.Open()
                sda = New SqlDataAdapter("Select * From NDR", conn1)
                dt = New DataTable()
                sda.Fill(dt)

            End Using
            For Each d In dt.Rows
                strings.Add(d(0).ToString)
            Next




        End Sub

        Private Sub NDRDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles NDRDataGridView.EditingControlShowing

            If NDRDataGridView.CurrentCell.ColumnIndex.Equals(0) Then
                Dim TextBox As TextBox = TryCast(e.Control, TextBox)
                TextBox.AutoCompleteCustomSource = strings
                TextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
                TextBox.AutoCompleteMode = AutoCompleteMode.Suggest
                AddHandler TextBox.TextChanged, AddressOf texte

            End If

        End Sub

        Private Sub texte(ByVal sender As Object, ByVal e As EventArgs)
            Dim TextBox As TextBox = TryCast(sender, TextBox)
            If Strings.Contains(TextBox.Text) Then
                Dim a = strings.IndexOf(TextBox.Text)
                Me.NDRDataGridView.CurrentRow.Cells(1).Value = dt(a)(1)
                Me.NDRDataGridView.CurrentRow.Cells(2).Value = dt(a)(2)
                Me.NDRDataGridView.CurrentRow.Cells(3).Value = dt(a)(3)
            End If
        End Sub
    End Class

    do i have to mention 1st column in which i will type to search?where 

    Wednesday, April 10, 2019 5:56 AM
  • Hi,

    following code:

    Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection()

    For Each d In dt.Rows
                strings.Add(d(0).ToString)
            Next

    0 means index with the table first column.My code doesn't work? Is there an error?

    Best Regards,

    Alex


    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.


    Wednesday, April 10, 2019 6:05 AM
  • it was working fine but now not working and not showing any error 

      

       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


            Using conn1 = New SqlConnection(constr)
                conn1.Open()
                sda = New SqlDataAdapter("Select * From NDR", conn1)
                dt = New DataTable()
                sda.Fill(dt)

            End Using
            For Each d In dt.Rows
                strings.Add(d(5).ToString)
            Next




        End Sub

      Private Sub NDRDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles NDRDataGridView.EditingControlShowing


            If NDRDataGridView.CurrentCell.ColumnIndex.Equals(0) Then
                Dim TextBox As TextBox = TryCast(e.Control, TextBox)
                TextBox.AutoCompleteCustomSource = strings
                TextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
                TextBox.AutoCompleteMode = AutoCompleteMode.Suggest
                AddHandler TextBox.TextChanged, AddressOf texte

            End If



        End Sub

       Private Sub texte(ByVal sender As Object, ByVal e As EventArgs)
            Dim TextBox As TextBox = TryCast(sender, TextBox)
            If strings.Contains(TextBox.Text) Then
                Dim a = strings.IndexOf(TextBox.Text)
                NDRDataGridView.CurrentRow.Cells(1).Value = dt(a)(1)
                NDRDataGridView.CurrentRow.Cells(2).Value = dt(a)(2)
                NDRDataGridView.CurrentRow.Cells(3).Value = dt(a)(3)
            End If
        End Sub


    Wednesday, April 10, 2019 6:32 AM
  • is there any possibility that i can transfer textbox data to datagrid .

    i tried below code 

    public bsData As New BindingSource

       Dim dtr As New DataTable

           

            dtr.Columns.Add(New DataColumn() With {.ColumnName = "hiddenid", .DataType = GetType(Integer),
                             .AutoIncrement = False, .AutoIncrementSeed = False})
            dtr.Columns("hiddenid").ColumnMapping = MappingType.Hidden


            dtr.Columns.Add(New DataColumn() With {.ColumnName = "autonumber", .DataType = GetType(String)})
            dtr.Columns.Add(New DataColumn() With {.ColumnName = "location", .DataType = GetType(String)})
            dtr.Columns.Add(New DataColumn() With {.ColumnName = "date", .DataType = GetType(String)})
     

    1      bsData.DataSource = dtr
     

     2     NDRDataGridView.DataSource = bsData

     

     If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then

                If Not String.IsNullOrWhiteSpace(HiddenidTextBox.Text) Then
                    CType(bsData.DataSource, DataTable).Rows.Add(New Object() {Nothing, AutonumberTextBox1.Text, LocationTextBox.Text, DateTextBox1.Text})
                    bsData.MoveLast()
                End If

            End If

    this code work fine if i use it with one table ..... like if i use it with textbox and press enter then it will add values of textboxes to datagrid

    but when i use it with relationship tables , it hide data of FK table but if i remove LINE 1 AND LINE 2 (mentioned in codes)

    then i can able to see the FK data.

    Wednesday, April 10, 2019 6:37 AM
  • it was working fine but now not working and not showing any error 

      

       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


            Using conn1 = New SqlConnection(constr)
                conn1.Open()
                sda = New SqlDataAdapter("Select * From NDR", conn1)
                dt = New DataTable()
                sda.Fill(dt)

            End Using
            For Each d In dt.Rows
                strings.Add(d(5).ToString)
            Next




        End Sub

      Private Sub NDRDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles NDRDataGridView.EditingControlShowing


            If NDRDataGridView.CurrentCell.ColumnIndex.Equals(0) Then
                Dim TextBox As TextBox = TryCast(e.Control, TextBox)
                TextBox.AutoCompleteCustomSource = strings
                TextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
                TextBox.AutoCompleteMode = AutoCompleteMode.Suggest
                AddHandler TextBox.TextChanged, AddressOf texte

            End If



        End Sub

       Private Sub texte(ByVal sender As Object, ByVal e As EventArgs)
            Dim TextBox As TextBox = TryCast(sender, TextBox)
            If strings.Contains(TextBox.Text) Then
                Dim a = strings.IndexOf(TextBox.Text)
                NDRDataGridView.CurrentRow.Cells(1).Value = dt(a)(1)
                NDRDataGridView.CurrentRow.Cells(2).Value = dt(a)(2)
                NDRDataGridView.CurrentRow.Cells(3).Value = dt(a)(3)
            End If
        End Sub


    Hi,

    As you can see from your code, you use the sixth column of the invoice table as an index.Are you sure your invoice table has data?

    Best Regards,

    Alex


    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.

    Wednesday, April 10, 2019 7:00 AM
  • yes i have data in tables ...

    can u check my other question because if that can work then i can use that method (data from textbox to datagrid)

    Wednesday, April 10, 2019 7:32 AM
  • waiting for replyyy
    Wednesday, April 10, 2019 7:33 AM
  • Hi,
    I don't know who unterstand your problem.

    If you want to set a lookup in your DataGridView you can use a DataGridViewComboBoxColumn like this:

    Public Class Form15
    
      Private dgvLookup As New DataGridView With {.Top = 10, .Left = 10, .Height = 300, .Width = 400,
        .Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right,
        .AllowUserToAddRows = False, .AutoGenerateColumns = False}
    
      Private dgvData As New DataGridView With {.Top = 320, .Left = 10, .Height = 300, .Width = 500,
        .Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right,
        .AllowUserToAddRows = False, .AutoGenerateColumns = False}
    
      Private ds As DataSet
      Private bsLookup As New BindingSource
      Private bsData As New BindingSource
    
      Private WithEvents tbMaster As New TextBox With {.Text = "<new Lookup>", .Top = 10, .Left = 420,
        .Anchor = AnchorStyles.Top Or AnchorStyles.Right}
    
      Private WithEvents tbChild As New TextBox With {.Text = "<new Data>", .Top = 320, .Left = 520,
        .Anchor = AnchorStyles.Top Or AnchorStyles.Right}
    
      Private Sub Form15_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Form size
        Me.Height = 700
        Me.Width = 800
        ' add controls
        Me.Controls.AddRange(New Control() {dgvLookup, tbMaster, dgvData, tbChild})
        ' get Data and bind 
        ds = GetDataSet()
        bsLookup.DataSource = ds
        bsLookup.DataMember = "Lookup"
        dgvLookup.DataSource = bsLookup
        bsData.DataSource = ds
        bsData.DataMember = "Data"
        dgvData.DataSource = bsData
        ' design DataGridViews
        dgvLookup.Columns.Add(New DataGridViewTextBoxColumn With {.HeaderText = "Lookup text", .DataPropertyName = "LookupText"})
        '
        With dgvData.Columns
          .Add(New DataGridViewComboBoxColumn With {.HeaderText = "Looukup",
               .DataPropertyName = "FK", .DisplayMember = "LookupText", .ValueMember = "ID", .DataSource = bsLookup})
          .Add(New DataGridViewTextBoxColumn With {.HeaderText = "autonumber", .DataPropertyName = "autonumber"})
          .Add(New DataGridViewTextBoxColumn With {.HeaderText = "location", .DataPropertyName = "location"})
          .Add(New DataGridViewTextBoxColumn With {.HeaderText = "date", .DataPropertyName = "date"})
        End With
      End Sub
    
      Private Sub tbMaster_KeyDown(sender As Object, e As KeyEventArgs) Handles tbMaster.KeyDown
        If e.KeyCode = Keys.Enter Then
          ds.Tables("Lookup").Rows.Add(Nothing, CType(sender, TextBox).Text)
        End If
      End Sub
    
      Private Sub tbChild_KeyDown(sender As Object, e As KeyEventArgs) Handles tbChild.KeyDown
        If e.KeyCode = Keys.Enter Then
          With CType(bsData.AddNew, DataRowView)
            .Row("location") = CType(sender, TextBox).Text
            .Row("FK") = CType(bsLookup.Item(0), DataRowView)("ID")
          End With
        End If
      End Sub
    
      Private Function GetDataSet() As DataSet
        ' simulate data loading
        Dim rnd As New Random ' for random lookup
        ' instatiate new Dataset
        Dim ds As New DataSet
        ' Lookup table
        Dim dtLookup As New DataTable("Lookup")
        With dtLookup
          With .Columns
            With .Add("ID", GetType(Integer))
              .AutoIncrement = True
              .AutoIncrementSeed = -1
              .AutoIncrementStep = -1
            End With
            .Add("LookupText", GetType(String))
          End With
          For i = 1 To 10
            .Rows.Add(Nothing, $"LookupText {i}")
          Next
        End With
        ' Child
        Dim dt As New DataTable("Data")
        With dt
          With .Columns
            .Add(New DataColumn() With {.ColumnName = "hiddenid",
                       .DataType = GetType(Integer),
                       .AutoIncrement = True,
                       .AutoIncrementSeed = -1,
                       .AutoIncrementStep = -1,
                       .ColumnMapping = MappingType.Hidden})
            .Add("FK", GetType(Integer))
            .Add(New DataColumn() With {.ColumnName = "autonumber", .DataType = GetType(String)})
            .Add(New DataColumn() With {.ColumnName = "location", .DataType = GetType(String)})
            .Add(New DataColumn() With {.ColumnName = "date", .DataType = GetType(String)})
          End With
          For i = 1 To 20
            .Rows.Add(Nothing, -rnd.Next(1, 11), $"autonumber {i}", $"location{i}", $"date {i}")
          Next
        End With
        ' Dataset and Relation
        With ds
          With .Tables
            .Add(dtLookup)
            .Add(dt)
          End With
          .Relations.Add("Rel", dtLookup.Columns("ID"), dt.Columns("FK"))
        End With
        Return ds
      End Function
    
    End Class


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks


    Wednesday, April 10, 2019 7:48 AM
  • yes i have data in tables ...

    can u check my other question because if that can work then i can use that method (data from textbox to datagrid)

    I can't understand what you mean from textbox to datagrid,like this?

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From Student", conn)
                dt = New DataTable()
                sda.Fill(dt)
                bind.DataSource = dt
                DataGridView1.Datasource = dt
            End Using
            TextBox1.DataBindings.Add("Text", bind, "Name")
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            bind.MoveNext()
        End Sub
    End Class
    

    Best Regards,

    Alex


    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.

    Wednesday, April 10, 2019 8:08 AM
  • bro actually i was planning to make invoice in 2 ways 

    1 was searching for itemnumber in datagrid it self and populate other fields as u guide me before 

    2nd is searching items in itemnumber textbox and populate other textboxes and after i enter quantity and by pressing enter all data of textboxex including itemcode will get add in datagrid with is in relation to item table. 

    i am interested in 2nd method. 

    i tried it but the code i posted above was making issue with relationship table so i need any method of it .

    user type item code in textbox and after he get it, all related textboxes get populate and after enter qty when he press enter all data of textbox move to datagrid 

    Wednesday, April 10, 2019 9:29 AM
  • waiting for helpp
    Wednesday, April 10, 2019 12:12 PM
  • Wednesday, April 10, 2019 12:59 PM
  • Wednesday, April 10, 2019 1:02 PM
  • waiting for replyyy
    it will not help to keep saying you are waiting for a reply. Note that you should use a spell-checker too.

    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, April 10, 2019 2:16 PM
    Moderator
  • Your code is not in line with your question. 

    You talk about a "datagrid". A "DataGrid" can present relational data. But you are using a "DataGridView" that can only hold one row from a DataTable (Joined or not), 

    Therefore try to be clear what you do if you want to make a working program.

    I know that Microsoft sold the DataGridView as a replacement for the DataGrid. But that is not the case. The DataGridView replaces the MSFlexGrid. 

    https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/datagrid-control-overview-windows-forms


    Success
    Cor


    Wednesday, April 10, 2019 5:15 PM
  • i understand and please accept my apologies for writing datagrid instead of datagridview.

    please help me and solve my issue 

    Thursday, April 11, 2019 5:39 AM
  • its datagridview not datagrid 
    Thursday, April 11, 2019 5:40 AM
  • Hi,

    press ctrl

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection()
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With DataGridView1
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "itemcode"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "itemdescription"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "qty"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "price"})
            End With
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From invoice", conn)
                dt = New DataTable()
                sda.Fill(dt)
            End Using
            For Each d In dt.Rows
                strings.Add(d(0).ToString)
            Next
            TextBox1.AutoCompleteCustomSource = strings
            TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
            TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
            'TextBox1.DataBindings.Add("Text", bind, "itemcode", True, DataSourceUpdateMode.OnPropertyChanged)
            'TextBox2.DataBindings.Add("Text", bind, "itemdescription", True, DataSourceUpdateMode.OnPropertyChanged)
            'TextBox3.DataBindings.Add("Text", bind, "qty", True, DataSourceUpdateMode.OnPropertyChanged)
            'TextBox4.DataBindings.Add("Text", bind, "price", True, DataSourceUpdateMode.OnPropertyChanged)
    
        End Sub
    
    
    
        Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
            Dim a = strings.IndexOf(TextBox1.Text)
    
            If strings.Contains(TextBox1.Text) Then
    
                If e.Control = True Then
                    Me.DataGridView1.Rows.Add()
                    TextBox2.Text = dt.Rows(a)(1).ToString
                    TextBox3.Text = dt.Rows(a)(2).ToString
                    TextBox4.Text = dt.Rows(a)(3).ToString
                    Me.DataGridView1.Rows(a).Cells(0).Value = TextBox1.Text
                    Me.DataGridView1.Rows(a).Cells(1).Value = TextBox2.Text
                    Me.DataGridView1.Rows(a).Cells(2).Value = TextBox3.Text
                    Me.DataGridView1.Rows(a).Cells(3).Value = TextBox4.Text
    
                End If
            End If
    
    
        End Sub
    
    
    End Class
    

    Best Regards,

    Alex


    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, April 11, 2019 7:04 AM
  • ERROR 

    Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

    also

    i cant see related items in textboxes

    • Edited by Omi4u Thursday, April 11, 2019 9:55 AM
    Thursday, April 11, 2019 9:27 AM
  • ERROR 

    Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

    also

    i cant see related items in textboxes

    Thursday, April 11, 2019 1:04 PM
  • waiting for reply 
    Saturday, April 13, 2019 6:13 AM
  • hi Alex

    i was waiting for your reply. i have to finalize this project as soon as possible.

    Monday, April 15, 2019 5:23 AM
  • ERROR 

    Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

    also

    i cant see related items in textboxes

    Hi,

    My code doesn't use data binding, it runs successfully, are you asking me for this effect?

    Best Regards,

    Alex


    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.

    Monday, April 15, 2019 5:27 AM
  • yes your codes are working perfect but i need for data binding .... thanks in advance 
    Monday, April 15, 2019 5:33 AM
  • yes your codes are working perfect but i need for data binding .... thanks in advance 

    Hi,

    fix a few lines of code,it works well

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection()
        Dim a = 0
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With DataGridView1
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "itemcode"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "itemdescription"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "qty"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "price"})
            End With
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From invoice", conn)
                dt = New DataTable()
                sda.Fill(dt)
            End Using
            bind.DataSource = dt
            For Each d In dt.Rows
                strings.Add(d(0).ToString)
            Next
            TextBox1.AutoCompleteCustomSource = strings
            TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
            TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
    
    
            TextBox1.DataBindings.Add("Text", bind, "itemcode", True, DataSourceUpdateMode.OnPropertyChanged)
            TextBox2.DataBindings.Add("Text", bind, "itemdescription", True, DataSourceUpdateMode.OnPropertyChanged)
            TextBox3.DataBindings.Add("Text", bind, "qty", True, DataSourceUpdateMode.OnPropertyChanged)
            TextBox4.DataBindings.Add("Text", bind, "price", True, DataSourceUpdateMode.OnPropertyChanged)
    
        End Sub
    
    
    
        Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
    
    
            If strings.Contains(TextBox1.Text) Then
    
                If e.Control = True Then
                    DataGridView1.Rows.Add()
                    TextBox2.Text = dt.Rows(a)(1).ToString
                    TextBox3.Text = dt.Rows(a)(2).ToString
                    TextBox4.Text = dt.Rows(a)(3).ToString
                    Me.DataGridView1.Rows(a).Cells(0).Value = TextBox1.Text
                    Me.DataGridView1.Rows(a).Cells(1).Value = TextBox2.Text
                    Me.DataGridView1.Rows(a).Cells(2).Value = TextBox3.Text
                    Me.DataGridView1.Rows(a).Cells(3).Value = TextBox4.Text
                    a += 1
                End If
            End If
    
    
        End Sub
    
    
    End Class
    

    Best Regards,

    Alex


    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.

    Monday, April 15, 2019 7:25 AM
  • error 

    This causes two bindings in the collection to bind to the same property.
    Parameter name: binding

    Monday, April 15, 2019 9:29 AM
  • error 

    This causes two bindings in the collection to bind to the same property.
    Parameter name: binding

    your autonumberTextbox1 had bound?


    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.

    Monday, April 15, 2019 9:37 AM
  • No 

    if i remove 

    AutonumberTextBox1.DataBindings.Add("Text", bind, "autonumber", True, DataSourceUpdateMode.OnPropertyChanged)

    then this error will goto 

    locationtextbox1..................... 

    it keep transferring it i remove the error line

    let me share with you all codes

    Imports System.Data.SqlClient
    Public Class Form1
         Dim objdatareader As SqlDataReader
        Dim conn As New SqlConnection("Server= FILE-SERVER; Database = dbotest;Integrated Security = false;User ID=das;Password=0m3rP@ss")
        Dim cmd As New SqlCommand
        Dim cmdx As New SqlCommand
        Public bsData As New BindingSource
    
        Dim scAutoComplete As New AutoCompleteStringCollection
    
    
    
        Dim constr As String = ("Server= FILE-SERVER; Database = dbotest;Integrated Security = false;User ID=das;Password=0m3rP@ss")
        Dim conn1 As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection()
        Dim a = 0
    
    
    #Region "command"
        Sub autonumber()
            Dim autoID As Single
            conn.Open()
    
    
            cmd = New SqlCommand("select count(*) as autonumber from t1")
            cmd.Connection = conn
    
            objdatareader = cmd.ExecuteReader
    
    
            While objdatareader.Read
                autoID = Val(objdatareader.Item("autonumber").ToString + 1)
    
            End While
            Select Case Len(Trim(autoID))
                Case 1 : AutonumberTextBox.Text = "600" + Trim(Str(autoID))
                Case 2 : AutonumberTextBox.Text = "60" + Trim(Str(autoID))
                Case 3 : AutonumberTextBox.Text = "6" + Trim(Str(autoID))
            End Select
    
            conn.Close()
    
        End Sub
    
    
    
    #End Region
    
    
    
    
    
        Private Sub T1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles T1BindingNavigatorSaveItem.Click
            Me.Validate()
            Me.T1BindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.DbotestDataSet)
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            'TODO: This line of code loads data into the 'DbotestDataSet.NDR' table. You can move, or remove it, as needed.
            Me.NDRTableAdapter.Fill(Me.DbotestDataSet.NDR)
            'TODO: This line of code loads data into the 'DbotestDataSet.t1' table. You can move, or remove it, as needed.
            Me.T1TableAdapter.Fill(Me.DbotestDataSet.t1)
    
    
    
            Using conn1 = New SqlConnection(constr)
                conn1.Open()
                sda = New SqlDataAdapter("Select * From NDR", conn1)
                dt = New DataTable()
                sda.Fill(dt)
            End Using
    
            bind.DataSource = dt
    
            For Each d In dt.Rows
                strings.Add(d(0).ToString)
            Next
            AutonumberTextBox1.AutoCompleteCustomSource = strings
            AutonumberTextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
            AutonumberTextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
            'TextBox1.DataBindings.Add("Text", bind, "itemcode", True, DataSourceUpdateMode.OnPropertyChanged)
            'TextBox2.DataBindings.Add("Text", bind, "itemdescription", True, DataSourceUpdateMode.OnPropertyChanged)
            'TextBox3.DataBindings.Add("Text", bind, "qty", True, DataSourceUpdateMode.OnPropertyChanged)
            'TextBox4.DataBindings.Add("Text", bind, "price", True, DataSourceUpdateMode.OnPropertyChanged)
    
            AutonumberTextBox1.DataBindings.Add("Text", bind, "autonumber", True, DataSourceUpdateMode.OnPropertyChanged)
            LocationTextBox.DataBindings.Add("Text", bind, "location", True, DataSourceUpdateMode.OnPropertyChanged)
            DateTextBox1.DataBindings.Add("Text", bind, "date", True, DataSourceUpdateMode.OnPropertyChanged)
    
            HiddenidTextBox.DataBindings.Add("Text", bind, "hiddenid", True, DataSourceUpdateMode.OnPropertyChanged)
    
    
        End Sub
    
    
    
    
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            T1BindingSource.AddNew()
            autonumber()
    
    
            AutonumberTextBox1.Text = AutonumberTextBox.Text
    
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    
        End Sub
    
        Private Sub NameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameTextBox.TextChanged
    
        End Sub
    
        Private Sub HiddenidTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles HiddenidTextBox.KeyPress
            If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
    
                If Not String.IsNullOrWhiteSpace(HiddenidTextBox.Text) Then
                    CType(bsData.DataSource, DataTable).Rows.Add(New Object() {Nothing, AutonumberTextBox1.Text, LocationTextBox.Text, DateTextBox1.Text})
                    bsData.MoveLast()
                End If
    
            End If
        End Sub
    
        Private Sub HiddenidTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HiddenidTextBox.TextChanged
    
        End Sub
    
        Private Sub NDRDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles NDRDataGridView.CellContentClick
    
    
    
    
    
        End Sub
    
        Private Sub NDRDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles NDRDataGridView.EditingControlShowing
    
    
        End Sub
    
    
    
    
    
    
        Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
        End Sub
    
        Private Sub AutonumberTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles AutonumberTextBox1.KeyDown
    
    
            If strings.Contains(AutonumberTextBox1.Text) Then
    
                If e.Control = True Then
                    NDRDataGridView.Rows.Add()
                    HiddenidTextBox.Text = dt.Rows(a)(3).ToString
                    LocationTextBox.Text = dt.Rows(a)(4).ToString
                    DateTextBox1.Text = dt.Rows(a)(5).ToString
                    NDRDataGridView.Rows(a).Cells(2).Value = AutoidTextBox1.Text
                    NDRDataGridView.Rows(a).Cells(3).Value = HiddenidTextBox.Text
                    NDRDataGridView.Rows(a).Cells(4).Value = LocationTextBox.Text
                    NDRDataGridView.Rows(a).Cells(5).Value = DateTextBox1.Text
                    a += 1
                End If
            End If
    
    
        End Sub
    
        Private Sub AutonumberTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles AutonumberTextBox1.KeyPress
    
    
    
    
    
        End Sub
    
        Private Sub AutonumberTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AutonumberTextBox1.TextChanged
    
        End Sub
    End Class
    

    Monday, April 15, 2019 10:03 AM
  • Alex, all the time I see you basically stepping all over mods and other general forum etiquette. Like doing peoples homework for them when it is clearly even a sticky post. In my opinion you are a terrible forum moderator, you seem to be point farming which, i dont know, does that earn you a paycheck?

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Monday, April 15, 2019 7:11 PM
  • Hi ,

    Sorry for the late reply,I have been busy yesterday,add a SuspendBinding() and ResumeBinding()

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection()
        Dim i = 0
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With DataGridView1
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "itemcode"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "itemdescription"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "qty"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "price"})
            End With
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From invoice", conn)
                dt = New DataTable()
                sda.Fill(dt)
            End Using
            bind.DataSource = dt
            For Each d In dt.Rows
                strings.Add(d(0).ToString)
            Next
            TextBox1.AutoCompleteCustomSource = strings
            TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
            TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
    
    
            TextBox1.DataBindings.Add("Text", bind, "itemcode")
            TextBox2.DataBindings.Add("Text", bind, "itemdescription", True, DataSourceUpdateMode.OnPropertyChanged)
            TextBox3.DataBindings.Add("Text", bind, "qty", True, DataSourceUpdateMode.OnPropertyChanged)
            TextBox4.DataBindings.Add("Text", bind, "price", True, DataSourceUpdateMode.OnPropertyChanged)
    
        End Sub
    
    
    
        Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
    
    
            If strings.Contains(TextBox1.Text) Then
                Dim a = strings.IndexOf(TextBox1.Text)
                bind.SuspendBinding()
                TextBox2.Text = dt.Rows(a)(1).ToString
                TextBox3.Text = dt.Rows(a)(2).ToString
                TextBox4.Text = dt.Rows(a)(3).ToString
                If e.Control = True Then
                    Me.DataGridView1.Rows.Add()
                    Me.DataGridView1.Rows(i).Cells(0).Value = TextBox1.Text
                    Me.DataGridView1.Rows(i).Cells(1).Value = TextBox2.Text
                    Me.DataGridView1.Rows(i).Cells(2).Value = TextBox3.Text
                    Me.DataGridView1.Rows(i).Cells(3).Value = TextBox4.Text
                    i += 1
                    bind.ResumeBinding()
                End If
    
            End If
    
    
        End Sub
    
    
    End Class
    

    Best Regards,

    Alex


    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.

    Tuesday, April 16, 2019 2:05 AM
  • same error 

    Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

    Tuesday, April 16, 2019 6:28 AM
  • Hi,

    my code works well,I did not bind the dataGridview1 to any data,if you bound dt,try

    dt.rows.add()

    instead of

    datagridview1.rows.add()

    Best Regards,

    Alex


    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.

    Tuesday, April 16, 2019 6:52 AM
  • HI ALEX 

    thank you for your support . your codes are working but it only adding 1st row and when i try to add 2nd row from textbox it give error 

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    i am sharing with you a example file so you will understand and can able to fix the issues 

    here it is 

    https://1drv.ms/u/s!Aqjx5CNCnnObhWEzPp5W4sfCQyJn?e=weOFag

    Tuesday, April 16, 2019 7:33 AM
  • HI ALEX 

    thank you for your support . your codes are working but it only adding 1st row and when i try to add 2nd row from textbox it give error 

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    i am sharing with you a example file so you will understand and can able to fix the issues 

    here it is 

    https://1drv.ms/u/s!Aqjx5CNCnnObhWEzPp5W4sfCQyJn?e=weOFag

    Hi,

    I see what was wrong, you are binding the data source here. So you can't use :

    Datagridview1.rows.add()

    You can add a new row to DataGridview1 by modifying the data source, or Unbind add columns

    With NDRDataGridView
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "autonumber"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "hiddenid"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "location"})
                .Columns.Add(New DataGridViewTextBoxColumn With {.Name = "date"})
            End With

    Best Regards,

    Alex


    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.




    Tuesday, April 16, 2019 8:11 AM
  • thank you alex bro 

     but both datagridview is in relation and if i remove the binding then the relationship will not work 

    Tuesday, April 16, 2019 10:25 AM
  • Hi,

    You can define a data source yourself.

    Dim dt As New DataTable
            Dim bind As New BindingSource
            dt.Columns.Add("autonumber")
            dt.Columns.Add("hiddenid")
            dt.Columns.Add("location")
            dt.Columns.Add("date")
            bind.DataSource = dt
            NDRDataGridView.DataSource = bind

    use

    dt.rows.add()

    Best Regards,

    Alex


    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.

    Tuesday, April 16, 2019 11:17 AM
  • can u send me a sample code please . i mean where i have to enter above codes 
    Tuesday, April 16, 2019 11:49 AM
  • i tried but error 

     Private Sub AutonumberTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles AutonumberTextBox1.KeyDown


            Dim dt As New DataTable
            Dim bind As New BindingSource

            dt.Columns.Add("AutoidRLabel")
            dt.Columns.Add("AutoidLabel1")
            dt.Columns.Add("autonumber")
            dt.Columns.Add("hiddenid")
            dt.Columns.Add("location")
            dt.Columns.Add("date")
            bind.DataSource = dt
            NDRDataGridView.DataSource = bind


            If strings.Contains(AutonumberTextBox1.Text) Then
                Dim a = strings.IndexOf(AutonumberTextBox1.Text)
                bind.SuspendBinding()
                LocationTextBox.Text = dt.Rows(a)(2).ToString
                HiddenidTextBox.Text = dt.Rows(a)(3).ToString
                DateTextBox1.Text = dt.Rows(a)(5).ToString

                If e.Control = True Then

                    dt.Rows.Add()
                    Me.NDRDataGridView.Rows(i).Cells(2).Value = AutonumberTextBox1.Text
                    Me.NDRDataGridView.Rows(i).Cells(4).Value = LocationTextBox.Text
                    Me.NDRDataGridView.Rows(i).Cells(3).Value = HiddenidTextBox.Text
                    Me.NDRDataGridView.Rows(i).Cells(5).Value = DateTextBox1.Text
                    i += 1
                    bind.ResumeBinding()
                End If

            End If
        End Sub

    Tuesday, April 16, 2019 11:57 AM
  • Hi,

    Imports System.Data.SqlClient Public Class Form1 Dim constr As String = " Data Source=.\;Initial Catalog=alexDB;User Id=xx;Password=xx;" Dim conn As SqlConnection Dim sda As SqlDataAdapter Dim dt As New DataTable Dim dt2 As New DataTable Dim bind As New BindingSource Dim strings As AutoCompleteStringCollection = New AutoCompleteStringCollection() Dim i = 0 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim bind2 As New BindingSource dt2.Columns.Add("autonumber") dt2.Columns.Add("hiddenid") dt2.Columns.Add("location") dt2.Columns.Add("date") bind2.DataSource = dt2 DataGridView1.DataSource = bind2 Using conn = New SqlConnection(constr) conn.Open() sda = New SqlDataAdapter("Select * From invoice", conn) sda.Fill(dt) End Using bind.DataSource = dt For Each d In dt.Rows strings.Add(d(0).ToString) Next TextBox1.AutoCompleteCustomSource = strings TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest TextBox1.DataBindings.Add("Text", bind, "itemcode", True, DataSourceUpdateMode.OnPropertyChanged) TextBox2.DataBindings.Add("Text", bind, "itemdescription", True, DataSourceUpdateMode.OnPropertyChanged) TextBox3.DataBindings.Add("Text", bind, "qty", True, DataSourceUpdateMode.OnPropertyChanged) TextBox4.DataBindings.Add("Text", bind, "price", True, DataSourceUpdateMode.OnPropertyChanged) End Sub Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown If strings.Contains(TextBox1.Text) Then Dim a = strings.IndexOf(TextBox1.Text) bind.SuspendBinding() TextBox2.Text = dt.Rows(a)(1).ToString TextBox3.Text = dt.Rows(a)(2).ToString TextBox4.Text = dt.Rows(a)(3).ToString If e.Control = True Then dt2.Rows.Add() Me.DataGridView1.Rows(i).Cells(0).Value = TextBox1.Text Me.DataGridView1.Rows(i).Cells(1).Value = TextBox2.Text Me.DataGridView1.Rows(i).Cells(2).Value = TextBox3.Text Me.DataGridView1.Rows(i).Cells(3).Value = TextBox4.Text i += 1

    bind.ResumeBinding() End If End If End Sub End Class


    Best Regards,

    Alex


    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.


    Tuesday, April 16, 2019 12:43 PM
  • i tried but error 

     Private Sub AutonumberTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles AutonumberTextBox1.KeyDown


            Dim dt As New DataTable
            Dim bind As New BindingSource

            dt.Columns.Add("AutoidRLabel")
            dt.Columns.Add("AutoidLabel1")
            dt.Columns.Add("autonumber")
            dt.Columns.Add("hiddenid")
            dt.Columns.Add("location")
            dt.Columns.Add("date")
            bind.DataSource = dt
            NDRDataGridView.DataSource = bind


            If strings.Contains(AutonumberTextBox1.Text) Then
                Dim a = strings.IndexOf(AutonumberTextBox1.Text)
                bind.SuspendBinding()
                LocationTextBox.Text = dt.Rows(a)(2).ToString
                HiddenidTextBox.Text = dt.Rows(a)(3).ToString
                DateTextBox1.Text = dt.Rows(a)(5).ToString

                If e.Control = True Then

                    dt.Rows.Add()
                    Me.NDRDataGridView.Rows(i).Cells(2).Value = AutonumberTextBox1.Text
                    Me.NDRDataGridView.Rows(i).Cells(4).Value = LocationTextBox.Text
                    Me.NDRDataGridView.Rows(i).Cells(3).Value = HiddenidTextBox.Text
                    Me.NDRDataGridView.Rows(i).Cells(5).Value = DateTextBox1.Text
                    i += 1
                    bind.ResumeBinding()
                End If

            End If
        End Sub

    where is the error?

    Best Regards,

    Alex


    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.

    Tuesday, April 16, 2019 12:51 PM
  • its giving error leave it u really helped me alot alex and i learn alot from you

    can you share with me anything that can help me to learn and work with relationship between 2 tables and also in which i can add data ...... something like making invoice with invoice number, customer details and a way to enter items and at the end total price.  something like POS 

    Tuesday, April 16, 2019 12:54 PM
  • Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    Tuesday, April 16, 2019 1:04 PM
  • Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    Which line of code?

    Best Regards,

    Alex


    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.

    Tuesday, April 16, 2019 1:42 PM
  • Hi,

    I have added a row to the DataGridView using code below, there should be no such error.

    dt.Rows.Add()

    Best Regards,

    Alex


    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.

    Tuesday, April 16, 2019 1:47 PM
  • hi alex

    sorry i was little busy 

    i am going to test again and will update you shortly 

    Thursday, April 18, 2019 5:15 AM
  • Hi alex how r u 

    i made a complete example with items, customers etc to make you understand my issue you can download it from below link

    https://1drv.ms/u/s!Aqjx5CNCnnObhWIvAe1EIuvrXYev?e=IoXJUc

    please run the software and use invoice2 to see the error and issue while adding textboxes in datagrid 

    check invoice2

    Friday, April 19, 2019 11:07 AM
  • Hi alex how r u 

    i made a complete example with items, customers etc to make you understand my issue you can download it from below link

    https://1drv.ms/u/s!Aqjx5CNCnnObhWIvAe1EIuvrXYev?e=IoXJUc

    please run the software and use invoice2 to see the error and issue while adding textboxes in datagrid 

    check invoice2

    Friday, April 19, 2019 1:17 PM
  • waiting for your reply 
    Saturday, April 20, 2019 9:32 AM
  • Hi,

    I can't run your code because of the database,Where is your code error?

    Best Regards,

    Alex


    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.

    Tuesday, April 23, 2019 8:09 AM
  • database file is in the zip 

    you can only able to see and understand the error if you run it .. 

    Thursday, April 25, 2019 1:17 PM
  • database file is in the zip 

    you can only able to see and understand the error if you run it .. 

    I would look at it but unable to extract from a .rar file, only can work with .zip

    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

    Thursday, April 25, 2019 1:20 PM
    Moderator
  • converted to zip now 

    https://1drv.ms/u/s!Aqjx5CNCnnObhWPhwgLtpiuS9toR?e=f3e9PM

    Thursday, May 2, 2019 9:27 AM
  • Hi,

    I can't run your code,I suggest you still create a new Thread and then describe your issue in detail.

    Best Regards,

    Alex


    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, May 3, 2019 5:11 AM
  • can you please check my below script ... it not updating record not showing any error

      If AccountfromTextBox.Text <> "" And AmountTextBox.Text <> "" Then

            
                fields = "ID,accountfrom,accountto,amount"
                fvalue = IdTextBox.Text & "','" & AccountfromTextBox.Text & "','" & AccounttoTextBox.Text & "','" & AmountTextBox.Text
                query = "INSERT INTO coato (" & fields & ") VALUES ('" & fvalue & "')"
                cudfunctionNOmsg(query)
             
                updateQuery = "UPDATE coa set amount = amount + '" & AmountTextBox.Text & "'  WHERE accountname = '" & AccounttoTextBox.Text & "'"
               
                cudfunctionNOmsg(updateQuery)
             
              
                MsgBox("The " & AccountfromTextBox.Text & " Updated.")
                'update autonumber
              
                'Call AddNewToolStripMenuItem_Click(sender, e)
            Else


                MsgBox("Fill up the correct product in the empty fields inorder to save.")
               
                Beep()
            End If

            IdTextBox.Text = ""
        End Sub

    Saturday, May 4, 2019 6:35 AM
  • i solved this issue 

    now i have issue here 

      updateQuery = "UPDATE COA SET opening_balance = opening_balance + '" & TotalamountTextBox.Text & "'  WHERE AccountID = '" & Coa_idTextBox.Text & "'"

    instead of adding opening_balance with existing, it showing new value with old 

    example

    if i have opening balance of any account 500 and if i made any entry of 1000 then it must be 1500 but it showing me 5001000

    please help

    • Marked as answer by Omi4u Monday, May 27, 2019 11:25 AM
    Monday, May 6, 2019 8:02 AM
  • Hi Omi4u,

    I am glad to know that resolve the issue, if possible, could you please share your solution will beneficial to other communities who face the similar issue, for the new issue, based on forum policy, I would suggest that you could post a new thread.

    Best regards,

    Zhanglong


    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.

    Tuesday, May 14, 2019 5:36 AM
    Moderator