Solved

Datagrid and Textbox binding

Posted on 2004-10-27
354 Views
Last Modified: 2011-09-20
Hi,

I've created a custom control that reads data from a database and put the result in a dataset. I've binded the datagrid to the dataset.
Then I read the dataset (the columns, columnnames and types) to create dynamicly textboxes and labels as much as there are columns. I bind the textboxes to the dataset.
Everything is loading fine. When I run the application, I get my custom control with the datagrid and the textboxes. In the textboxes I can see the first row of the dataset.
Now I want to scroll through the dataset by selecting a new row in the datagrid. The textboxes must show the selected row.
How can I do that?

Thanx in advance
kGenius (ahum)
PS sorry for the poor grammar ;-)
0
Question by:kGenius
    6 Comments
     
    LVL 1

    Expert Comment

    by:jameskearney

    handle the datagrid rowchanged or rowselected event (cant remember which/what event specifically it has), and then in that event do

    textbox.text = ctype( currentRow.Item("columnName"), String)

    thats just off of the top of my head,

    is that any help at all?

    james
    0
     
    LVL 25

    Expert Comment

    by:RonaldBiemans
    If you have binded the textboxes to the same datasource as the grid it should happen automaticaly without any extra coding
    0
     
    LVL 25

    Expert Comment

    by:RonaldBiemans
    oeps pressed submit too soon,


    If you have binded the textboxes to the same datasource as the grid it should happen automaticaly without any extra coding.

    So if the data in the textboxes  does not scroll automatically with the grid then you have done something wrong,
    If you could post some code maybe we can see where you went wrong
    0
     
    LVL 25

    Accepted Solution

    by:
    to explain a little

    datagrid1.datasource = ds.tables(0)
    TextBox1.DataBindings.Add("Text", ds.tables(0), "yourcolumnname")

    will scroll

    datagrid1.datasource = ds.tables(0)
    dim dv as dataview = ds.tables(0).defaultview
    TextBox1.DataBindings.Add("Text", dv, "yourcolumnname")

    will not scroll

    although the seem to be bound to the same datasource, they aren't
    0
     
    LVL 7

    Author Comment

    by:kGenius
    Thanks,

    I've had this code: textbox1.DataBindings.Add("Text", ds.Tables(0).defaultview, "columnname")

    I've removed the .DefaultVieuw and everything is fine now !
    The table must be binded not a dataview, I see !

    thanks again,
    kGenius (a bit more :)
    0
     
    LVL 25

    Expert Comment

    by:RonaldBiemans
    Hi KGenius,

    You can bind your textboxes to the dataview but then your datagrid should also be binded to the dataview
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now