|
-
Jan 6th, 2022, 08:34 PM
#1
Thread Starter
Fanatic Member
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?
-
Jan 6th, 2022, 10:08 PM
#2
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.
-
Jan 7th, 2022, 10:49 AM
#3
Thread Starter
Fanatic Member
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.
-
Jan 7th, 2022, 08:53 PM
#4
Re: Databinding
 Originally Posted by gwboolean
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.
-
Jan 8th, 2022, 04:04 AM
#5
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.
-
Jan 8th, 2022, 08:35 AM
#6
Thread Starter
Fanatic Member
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.
-
Jan 8th, 2022, 01:36 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|