none
Datagridviw, Table, TextBox binding RRS feed

  • Question

  • Hi

    I have a simple situationn

    A Table1 with data from Database ( about 200 rows)

    Datagridview (DGV) bind to Table1

    Some TextBoxes in form Bind to DataTable Columns

    I'm able to Add new row from Form to Table1

    After adding the new row I select in the DGV the last row added and scroll to it.

    Everything works.

    The only problem is that the TextBoxes  after adding I get the DGV row selected BEFORE adding the new row 

    How to do to display in TextBoxes the last row ADDED


    Friday, January 12, 2018 4:18 PM

Answers

  • Thank you Karen

    what I needed was to set  BS.Position to the last row ID

    Now it works.


    Great, you may want to look at the following which is off topic for this question yet good stuff for when working with a BindingSource component

    Code sample 1: Custom BindingSource, covers locating, filtering and like conditions and code sample 2.


    Please remember to mark the replies as answers if they help and unmark 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.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Claudio111 Thursday, January 18, 2018 6:27 PM
    Saturday, January 13, 2018 12:07 PM
    Moderator
  • Thank you Karen
    • Marked as answer by Claudio111 Thursday, January 18, 2018 6:28 PM
    Thursday, January 18, 2018 6:28 PM

All replies

  • I firgot to sat that DGV and TextBox use a sane BindingSiuce BS1 to bind to Table1
    Friday, January 12, 2018 5:04 PM
  • Hi

    I have a simple situationn

    A Table1 with data from Database ( about 200 rows)

    Datagridview (DGV) bind to Table1

    Some TextBoxes in form Bind to DataTable Columns

    I'm able to Add new row from Form to Table1

    After adding the new row I select in the DGV the last row added and scroll to it.

    Everything works.

    The only problem is that the TextBoxes  after adding I get the DGV row selected BEFORE adding the new row 

    How to do to display in TextBoxes the last row ADDED


    Hi

    Some TextBoxes in Form Bind to DataTable Columns ???????

    What does that mean? Show the code - you always seems to ask us to guess what you are doing.


    Regards Les, Livingston, Scotland

    Friday, January 12, 2018 5:21 PM
  • It's unclear to what you mean

    "The only problem is that the TextBoxes  after adding I get the DGV row selected BEFORE adding the new row 

    How to do to display in TextBoxes the last row ADDED"

    Could you be more specific?


    Please remember to mark the replies as answers if they help and unmark 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.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, January 12, 2018 5:29 PM
    Moderator
  • ok let me explain the problem in other words

    I have the following Form

    I have a Binding Source (BS1) with BS1.DataSource = Table1 (from Database)

    The DGV ha DGV.DataSource = BS1

    The I have the 3 TextBoxes bind to BS1 with this code

    TxtNazioneID.DataBindings.Add("text", BS1, "NazioneID")
    		TxtSigla.DataBindings.Add("text", BS1, "Sigla")
    		TxtDescrizione.DataBindings.Add("text", BS1, "Descrizione")

    Everything works fine when I navigate on the DGV.

    Now I want to select a row in the DGV    RUNTIME with this code

    DGV.Rows(3).Selected = True

    In this case I get  the row(3) selected on the DGV but the TextBoxes show value of row(0)

    How to get the TextBoxes updated automatically with the value of row(3) ?

    Saturday, January 13, 2018 9:00 AM
  • Hello,

    The following could had been a simple reply but figured since you are learning I go the long route :-)

    When we bind data as being done here you need to change rows in the DataGridView using the BindingSource component.

    Using my simple example, I load data in my data class, hide identifier there rather than in the DataGridView as we need it but not seen and no reason at all to create a DataGridViewColumn, same for Country column yet we do want it to be data bound to a TextBox.

    Now in our form load

    Now to move to row 3 in the DataGridview I use the following and the TextBox for country is in sync with the DataGridView because they are both using the BindingSource, the TextBox knows nothing about the DataGridView and the DataGridview knows nothing about the BindingSource.

    bsCustomers.Position = 2

    To put things into perspective, let's search for a company name and position both the DataGridview and the TextBox using the following Find method.

    Dim position As Integer = bsCustomers.Find("CompanyName", "Eastern Connection")
    If position > -1 Then
        bsCustomers.Position = position
    End If

    Before

    After


    Please remember to mark the replies as answers if they help and unmark 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.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Claudio111 Saturday, January 13, 2018 11:35 AM
    • Unmarked as answer by Claudio111 Thursday, January 18, 2018 7:59 AM
    Saturday, January 13, 2018 10:58 AM
    Moderator
  • Thank you Karen

    what I needed was to set  BS.Position to the last row ID

    Now it works.


    Saturday, January 13, 2018 11:35 AM
  • Thank you Karen

    what I needed was to set  BS.Position to the last row ID

    Now it works.


    Great, you may want to look at the following which is off topic for this question yet good stuff for when working with a BindingSource component

    Code sample 1: Custom BindingSource, covers locating, filtering and like conditions and code sample 2.


    Please remember to mark the replies as answers if they help and unmark 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.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Claudio111 Thursday, January 18, 2018 6:27 PM
    Saturday, January 13, 2018 12:07 PM
    Moderator
  • Karen exscuse me,

    I cannot ask question anymore

    I get the message ; 

    • Your number of posts today has exceeded the limit.

    ANf this is not true.

    What should I do ?

    Thursday, January 18, 2018 7:59 AM
  • Karen exscuse me,

    I cannot ask question anymore

    I get the message ; 

    • Your number of posts today has exceeded the limit.

    ANf this is not true.

    What should I do ?

    Have never seen this before but will alert the higher level moderators and see what they say.

    Please remember to mark the replies as answers if they help and unmark 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.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, January 18, 2018 1:38 PM
    Moderator
  • Thank you Karen
    • Marked as answer by Claudio111 Thursday, January 18, 2018 6:28 PM
    Thursday, January 18, 2018 6:28 PM
  • Thank you Karen

    Hi Claudio111

    Someone needs to tell you.

    You very often mark your own inconsequential posts as the Answer. This is pointless for someone coming to the forum and searching for solutions. For example, someone finds your last post in this thread as an Answer to their problem - what use would that be to them?

    The suggested use of marking answers is to mark all the posts that actually assist and/or fully answer the question of the OP.

    You can and should mark your own posts as Answer if they do show something that go towards the solution.

    It is entirely wrong to mark a 'Thank you' post as an answer.


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, January 19, 2018 11:22 AM
    Friday, January 19, 2018 11:21 AM