Results 1 to 7 of 7

Thread: [2005] Binding to DataRow

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    [2005] Binding to DataRow

    After planning the layout for my form and building the form, I have come to find out that you cannot bind to a datarow object.

    My form has a mock grid made up of rows of textboxes. I could not get the DGV to fit on this screen and have it look like I wanted, so I made my own grid of sorts. Now, I need to bind this to a DataTable. I figured that what I would do is loop through the rows and have 9 DataRow objects that are form-level variables and then bind each row of textboxes to its appropriate DataRow. Now that I know I cannot bind to a DataRow, I am out of ideas for how to bind this information.

    Any ideas for how to bind this up would be greatly appreciated!!
    My.Settings.Signature = String.Empty

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Binding to DataRow

    Like this:
    Textbox.DataBinding.Add ("Text",yourDataTable,"ColumnName")

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] Binding to DataRow

    But, the main question is how do I bind each row of textboxes to a specific row in the datatable all being bound at the same time?

    I guess I could create multiple DataTable objects, each with the necessary DataRow. That seems to be a little much.
    My.Settings.Signature = String.Empty

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Binding to DataRow

    Woah! Hold on there.... what the he-???

    tell me again, WHY the grid won't work?
    It wouldn't FIT? .... how does it not fit, when the text boxes do?

    what happens when you start returning more rows than you have text boxes for? ...

    If you are dealing with multiple rows, you really should have a grid, not a bunch oftext boxes....
    I thought you were only binding one row (out of a DS) to a set of boxes... I didn't realize that you want to do ALL of the rows too....
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] Binding to DataRow

    LOL. I know, I know. This is what is going on.

    1 - I have too many columns of data to fit horizontally without having to scroll. The customer does not want to scroll. They want me to put the extra columns that are read-only at the bottom of the form. (I have implemented a backcolor and bold text tracking mechanism for them to quickly loook at the bottom of the form to see the current row.)

    2 - The customer wants all data entry forms to use the Courier font so that users who are typing in data can see how much space they have left. (This is the first app I have ever written where this was a requirement.) The DGV does not support font changing.

    That all aside there should really be 2 DGVs on this screen with another separate row for freight. These would all have to be lined up nice and neat. Since I have hardcoded the limit of 8 rows being shown on the screen due to the ReadOnly items at the bottom, I would have to set a limit on the rows in the DGV that contained the additional record data.
    Last edited by Aspnot; Sep 5th, 2006 at 02:22 PM.
    My.Settings.Signature = String.Empty

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] Binding to DataRow

    At first, it seemed like this should be a simple setup. That is, until I found out I could not bind to a DataRow.

    I could go back and setup DGVs and wire up enough code to make the tracking, row limit, etc. work.
    My.Settings.Signature = String.Empty

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Binding to DataRow

    I really think that this is all a dodgy setup, but in short you simply bind your single DataTable to multiple BindingSources and then bind the BindingSources to the appropriate controls. If you have N rows of TextBoxes then you need N BindingSources. You bind each row of TextBoxes to a different BindingSource with each TextBox in the row bound to a different column. You then set the Position property of each BindingSource to the index of the row that you want the bound TextBoxes to display.

    What I think would be a slightly better idea would be to have the grid show some columns and have one set of TextBoxes that shows the other columns for the row selected in the grid. That way you only need one BindingSource for the grid and the TextBoxes. As the selected row changes in the grid it will set the Position property of the BindingSource and thus automatically update the data displayed in the TextBoxes. I'm still not convinced that that's the best implementation but it sounds like an odd spec so an odd solution may be required.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width