Results 1 to 7 of 7

Thread: Databinding

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Databinding

    I have been attempting to figure out how to use databinding with variables, instead of controls. I keep looking up information on this and what I can understand only further confuses me.

    I had thought that this would be easy... but, as usual, I really fail to get it.

    So can someone explain to me how one could achieve that?

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

    Re: Databinding

    The whole point of data-binding in Windows Forms is to bind data to the UI. At the heart of it is the System.Windows.Forms.Binding class. If you read the documentation for that class, the fact that it has a Control property should make it fairly clear that a control has to be at one end of the binding.

    What exactly are you expecting to happen? Are you looking to set the variable when the data source changes? If so then just handle the appropriate event of the data source and set the variable in the event handler. That's what the Binding class does, but it does it in a very generic way, using Reflection.

    If you're looking for a data source to be updated when a variable changes then how could that possibly work? Data-binding only works because of events. Data can be pushed from a control to a data source because the control raises an event when the appropriate property changes. A variable has no events or properties of its own.
    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Re: Databinding

    I have no expectations at all. All I want to know is if and how one could bind with a variable? In this case I have a column that has data that I use but has no place on the form. I could leave it there in a disabled label, but I would rather assign it to a variable and let it do it's own thing out of sight.

    The datum is used with an OFD that points to the directory location where a set of files are stored. It is established when the record is created and never changed. While the datum is used, it is nothing that needs to be displayed on the form and does not change. I am currently using a label to hold the datum. I would like to just keep the datum in the background. I do know that if I make the label invisible that it will no longer bind. That seems odd and rather poorly designed to me, but it is what it is.

    Basically, I have found that putting the datum into a control and displaying it on the form is not what I want to do. That datum just sits there until the user would want to open the folder where a set of files are located, at which time the user clicks a button, which instructs the OFD to use the datum to locate the directory and open it for display.

    I am sure that there are many easy ways to handle that. I just don't know any of them and my perusal of numerous threads/reference content has not yielded anything that I could comprehend.

    It was my thought that I could just create a variable and bind the datum to the variable at the same time that I am binding the data from the other columns to their respective controls. I had already figured out that this is difficult and beyond my lack of skills.

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

    Re: Databinding

    Quote Originally Posted by gwboolean View Post
    All I want to know is if and how one could bind with a variable?
    Then your issue is resolved, because I have already explained that one wouldn't because one can't.
    Last edited by jmcilhinney; Jan 7th, 2022 at 09:31 PM.
    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

  5. #5
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    774

    Re: Databinding

    If the data doesn't change why would you need to bind it to anything? Just load it once into something like a List(Of String). Do you have a DataGridView on your form? My preference would be to include the datum column in the DGV and then hide it if you don't want the user to see it. This is particularly useful during development. Show everything to begin with and then hide the column in the release version.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Re: Databinding

    I have already explained that one wouldn't because one can't
    Sorry to hear that. Perhaps you might be willing to share how one might be able to easily deal with datum that is contained in a record that you want to use, but do not want to bind to a control on a form?

    Just load it once into something like a List(Of String)
    Thanks. I am not familiar with that, but I will do some study of and see if I can make it work... or alternatively, you might consider an explanation of how this might work.

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,508

    Re: Databinding

    You would reset the variable when a specific Event happened. If your using a bindingsource then that would probably be the PositionChanged Event. If not then use what ever Event is appropriate.

Tags for this Thread

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