|
Can someone assist me in how to get data binding to work across multiple forms. Here is the scenario: I am using a dataset with about 20 tables. I have a central form where i display read only lists of about 10 tables. The user selects an item from any displayed list to go to another form where the user can edit the item or go deeper into other related tables.
Unfortunately, i cannot get the binding to work. I tried passing the binding source it didn't work. I keep getting constraint errors. Also, the data is not showing up (as if the actual reference is not valid).
I am new at this so i am lost as to how to proceed. I have looked in books and articles but no help there. All the books or articles provide overly simplified examples.
If anyone can help, i thank you in advance.
wjprice
|
|
|
|
|
you would have to instantiate(sp?) an instance of each form, with public controls(bad idea) then you could access the controls to databind them, and when you wanted to show that perticular form use the instance you already have to load it, not necessarily the best idea...another idea is to load a dataset with all of your data in different datatables(you probably already do this) and then pass the dataset to a public property on the form before you call form.show() so that when you call form.show and the form_Load event fires you can use the dataset you passed to load any data that form needs.
something like :
form frm = new form();
frm.DataSetProperty = dataSet;
frm.Show();
and in form_Load you just bind whatever controls you need based on the tables in the dataset, you could just pass dataTables, but it sounds like you need more than one table per form.
hope this helps.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thank you for your suggestion. I tried the suggestion you mentioned: setting the dataset of the second form to the dataset of the first form.
Unfortunately, it did not work. When i tried this the list that i was using to show all items in the table was empty.
If i keep the dataset independent of the first form i would see the (newly entered items) in the list on the second form. But the first form would not show these items. On closing the app and getting back in both lists (first and second form) would show the newly entered items.
Somehow passing a reference to the dataset to the second form is not actually "happening". That's where i am "stumped".
by the way, i am using only a test app at this point. Two forms only. My dataset has an empty table that i am using to find a way around this.
Here is the code i used on the first form:
FormSite form = new FormSite();
form.ePaDateSet = this.ePaDataSet;
form.Show();
On the second form i have the dataset, bindingsource, and tableadapter, and a listbox. I used drag and drop to set up the listbox from the data source window.
Again, i do appreciate your help in this matter.
wjprice
|
|
|
|
|
i never use the drag n drop setup for that stuff so i dont know how it sets things up..i usually use dataviews to bind to controls
DataView dv = dataSet.Tables["tableName"].DefaultView;
you can do sorting here with the dv.Sort property
lstBox.DataSource = dv;
lstBox.DataBind();
I've never used a table adapter. Once you alter the list you'll have to re-bind each control that references the dataset, so that they read the new data, it wont happen automatically, i dotn know how you are adding things to the data but if you arent using the list box to do it you'll have to call its databind method (assuming the dataset is updated, if not you'll have to get the data from the database and rebind that way). It could be loosing the refernce to the dataset in the first form when the first form goes away. try this:
wjprice wrote: FormSite form = new FormSite();
form.ePaDateSet = this.ePaDataSet.Copy();
form.Show();
that should create another instance of the dataset if you watned to keep one on each form, but you may have issues with them getting out of synch, so keeping one dataset is a good idea, if possible.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I will try the dataview method. I am beginning to realize that the automatic method of using binding sources was not meant for "actual" usage but is perhaps just a "gotcha". All the books and articles i have read use your method. I have refrained from that since it requires a lot of manual coding. But i realize now that i have to bite the bullet and do it.
Thanks for getting me started. I will need to do a lot of practice. ...and since i need to do things the manual way i may as well go into objects and use data libraries as well. I didn't want to go to all this but perhaps there is no alternative when programming for the .net.
Again, thanks
wjprice
|
|
|
|
|
any Automatic way is just the IDE generateing code for you, which you can call whenver you need to. I dont know what your exact requirements are, but using the data view method should not require too much extra coding, and this way you'll know and have control over what is actually going on which helps more in the long run. Glad i could be of help.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi All,
I have DatetimePickerControl and i want Displaying a Time format Property set to Maximum Upto 30:00:00 minimaum time is set to 06:00:00
How to do..Please tell me...
Thanks
Somasundaram G
|
|
|
|
|
I don't think you can unless you write your own class, perhaps derived from the existing one.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I guess your answer was not helpful, whatever that means
led mike
|
|
|
|
|
I am getting used to it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi ...
Here i am working on the windows application with vb.net coding.Right now i am giving the navigation to using full path like ("C:\abc\abcproject\user.html") but i wanted to give up from my project ..all my folders which are required path in my project .like user folder contains user.html....can anbody help me to solve this problem..
Your's Lovinlg
Charan
|
|
|
|
|
charanbura wrote: ("C:\abc\abcproject\user.html")
This sort of conflicts with
charanbura wrote: Here i am working on the windows application
html is normally web applications. If so, then the tilde (~) denotes the root of your website, so you can use relative paths like ~\images\logo.gif and the web servier will know where to look
Hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi Bob,
Thanks for a lot it's working ..
Charan
|
|
|
|
|
Hi, I'm trying to fire an event when a NativeWindow is double-clicked. I am not inheriting from it so i can't use the WndProc . I can of course easily get the Handle. Does anyone know anything in the Windows API which I can use to detect a double click?
Thanks,
Chris
|
|
|
|
|
Hullo People!
there probably is a very easy way to solve this problem....
I am working with the treeview control in .net 2.0 windows forms.
I have two tab pages on a form. the first one has a treeview control and the second one has mostly textboxes.
When i navigate or click the second tab the selected node on the treeview control is no longer highlit although it remains selected (i have set hideselection to false).
How do i get the selected treeview node to be highlit when i navigate back to the first tab.
I have tried setting the treeview1.SelectedNode property...doesnt work!!
Thanks & regards
Romi
modified on Sunday, June 15, 2008 5:56 AM
|
|
|
|
|
hi all,
Please help me.I want to change interface through CSS file of Windows Form(its possible or not) in C#.Net window based application. If you have solution please tell me.If you have a another view for changing interface of multiple forms through any tool or form in the .net2.0.
<div class="ForumMod">modified on Saturday, June 14, 2008 3:19 AM</div>
|
|
|
|
|
You are totally confused here. CSS (Cascading Style Sheets) are ONLY used in web based applications, you CANNOT use them in winforms
Bob
Ashfield Consultants Ltd
|
|
|
|
|
|
Remove the title bar from the form by setting its FormBorderStyle to "none".
Then create your own title bar from scratch.
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
|
|
|
|
|
I'm using the web browser control to automate loading a web page, and I need to be able to close any dialogs that it opens up. I'm using the IDocHostShowUI to capture alert and confirm dialogs, but there doesn't seem to be anything to do for prompt dialogs. I'm looking for an approach to do something similar with that dialog, or at least be able to capture when it is created and close it using old school windows methods.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Hi
DataSet with 14 columns. (Only 1 row).
Form with 14 textboxes.
While initialising, each textbox is bound to the dataset:
txtWhatever.Databindings.Add("Text", dsValues, "TableName.ColumnName");
Each textbox displays the values from the dataset.
Changing the values in a textbox does not change the dataset. According to all documentation, it should.
Why won't it work with me?
I don't want to display the data in a single-row datagridview,
because it doesn't really make sense to the user.
Otherwise, I'll have to use no databinding, and on form load populate each textbox, and update the dataset on loss of focus for each textbox.
Thanks,
Nigel
|
|
|
|
|
Did the value get set back into the value in the dataset after focus left the textbox?
Have you tried with DataSourceUpdateMode set to OnPropertyChanged?
|
|
|
|
|
The dataset has no changes no matter what I try.
And yes, I have tried:
txtName.DataBindings.Add("Text",ds, "UserList.Name",true,DataSourceUpdateMode.OnPropertyChanged);
Made no difference.
I have also tried using a binding source, with breakpoints in the parse and format methods, and both get called, but the dataset remains unchanged.
While experimening, I found that a different dataset that does get updated if I use a datagridview does not get updated if I use a textbox.
|
|
|
|
|
Not sure if it's already solved for you, maybe check if the fields are readonly??
|
|
|
|
|
No, the fields are not read-only.
Because this problem is/was holding my project up, I have resorted to populating the textboxes one-by-one from the dataset, doing validating on the textboxes one-by-one, and then writing the values back to the dataset.
This does set HasChanges to true, and the changes are saved back to the database.
So I can use the table, but not an elegant way to handle things. Especially as the deal includes the source-code.
Maybe a SharpDevelop bug? Searching this forum and MSDN doesn't show anyone else with the problem, but then I imagine not many people use simple-binding to a dataset - mostly I see it where they use textboxes to change values in a gridview. I can get that to work, but then I'd have to use an invisible gridview, which is not really a better solution!!!
Nigel
|
|
|
|