|
-
Oct 21st, 2011, 02:19 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Clear Tables/Ctrls to open new File
I am using TextFieldParser to read a .txt file and create a DataTable
I then filter the table and create 4 new tables
I then bind those tables to BindingSources
Then Bind ComboBoxs to the BindingSource
Then bind TextBoxes to BindingSource
I like the user to be able to Open a new file without having to close the program
So upon opening a new file I have a sub routine that clears the tables the rows and the columns of each table as well the DataBindings to each control
The problem is once I do the Text Binding as such
Me.list1_MLStxt.DataBindings.Add("Text", Subject_Values.BindingSource1, Form10.mls_txt.Text)
Then when I open a new file I get an error message
conversion from string"""" to type double is not valid.
If I never perform the binding I can open and reopen different files without a problem. So this is causing me to think that the problem is with the way I am clear something? But I am obviously not sure
Is there something I am missing to clear everything properly in order to open and read and bind a new file?
Thanks for any suggestions
-
Oct 21st, 2011, 02:46 AM
#2
Re: Clear Tables/Ctrls to open new File
Do the different files all have the same structure or do they differ. If they differ then you will have to remove all the old bindings first, prepare all the data and then add new bindings. If they are the same then I would suggest that you just use one DataTable the whole time. You can bind that one DataTable to all the BindingSources and then use them to do the filtering. When you want to reload you simply Clear the DataTable and then repopulate. The columns won't change so the bindings don't have to either.
-
Oct 21st, 2011, 02:17 PM
#3
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
Thanks for the feedback,
As far as the structure they are similiar in that they have the same amount of columns, sometimes the column name is different and obviously they have different information and more or less rows. From my understanding of the documentation:
The Clear method removes all elements from the underlying list represented by the List property and sets the Count property to zero.
I thought the following code would be doing that?
Code:
For Each ctrl As Control In Listing.Controls
If TypeOf ctrl Is TextBox Then
CType(ctrl, TextBox).DataBindings.Clear()
If TypeOf ctrl Is ComboBox Then
CType(ctrl, ComboBox).DataBindings.Clear()
End If
End If
Next
-
Oct 21st, 2011, 07:50 PM
#4
Re: Clear Tables/Ctrls to open new File
First up, are all the controls direct children of Listing?
Second, you have your if statement looking for ComboBoxes inside your If statement looking for TextBoxes. If you are inside the first If block then you know that the control is a TextBox, so how can it possibly be a ComboBox? You need one If...ElseIf block, not two nested If blocks.
-
Oct 21st, 2011, 11:59 PM
#5
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
I am a bit emabarrassed to say I dont know if they are children, I dont understand that concept. They are all on the form called "Listing"
thanks for the heads up on the if statement big duh on my part
-
Oct 22nd, 2011, 12:11 AM
#6
Re: Clear Tables/Ctrls to open new File
That code is referring the default instance of that Listing form class. Is it actually the default instance that you have displayed? If you want to understand what default instances are then follow the Blog link in my signature and read my post on the subject.
Where is that code located? Is it also in that same form? If so then you should be using Me to refer to the current instance of the current type.
-
Oct 22nd, 2011, 12:25 AM
#7
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
The clear code is located on form1, which is start-up form and the form where user selects file using OFD
before i call the OFD I call the clear code
The bindings take place upon loading form2(Listing) if the user want to select a new file to open the go back to form1
-
Oct 22nd, 2011, 12:41 AM
#8
Re: Clear Tables/Ctrls to open new File
Show us the code in the first form that displays the second. Does the second form get closed between files?
-
Oct 22nd, 2011, 12:50 AM
#9
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
Code:
Private Sub ListingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListingsToolStripMenuItem.Click
'hides current form and displays the listing form (form2)
If Me.ToolStripStatusLabelFileName.Text <> "File Name" Then
If ValAdjstments() = False Then
Exit Sub
End If
If Subj_Val() = False Then
Exit Sub
End If
'loadlistings()
loadsubjectlistingform2()
Calcadjustlist1()
Calcadjustlist2()
Calcadjustlist3()
Listing.GLAformattext1()
Listing.GLAformattext2()
Listing.GLAformattext3()
Listing.total()
Listing.total2()
Listing.total3()
Me.Hide()
Try
Listing.Show()
Catch
MsgBox("Required Data Fields are Missing", MsgBoxStyle.Information)
End Try
ElseIf CBool(MessageBox.Show("No Data File Has Been Selected", "Please Select a Data File", MessageBoxButtons.OK)) Then
End If
Code:
Public Sub LoadForm2()
Me.ToolStripStatusLabel2.Visible = True
Me.ToolStripProgressBar1.Visible = True
Me.ToolStripProgressBar1.Value = 40
loadsubjectlistingform2() 'loads form2 with subject property values
Me.ToolStripProgressBar1.Value = 45
Loadsubjectsoldsform3()
Me.ToolStripProgressBar1.Value = 50
Listing.ListingsDatabinding()
Me.ToolStripProgressBar1.Value = 55
Listing.list1cmbo.DataSource = Me.BindingSource1
Me.ToolStripProgressBar1.Value = 60
Listing.list1cmbo.DisplayMember = "NewAddress"
Listing.list1cmbo.ValueMember = "NewAddress"
Listing.list1cmbo.SelectedIndex = 0
Me.ToolStripProgressBar1.Value = 65
Listing.list2cmbo.DataSource = Me.BindingSource2
Listing.list2cmbo.DisplayMember = "NewAddress"
Listing.list2cmbo.ValueMember = "NewAddress"
Listing.list2cmbo.SelectedIndex = 1
Me.ToolStripProgressBar1.Value = 70
Listing.list3cmbo.DataSource = Me.BindingSource3
Listing.list3cmbo.DisplayMember = "NewAddress"
Listing.list3cmbo.ValueMember = "NewAddress"
Listing.list3cmbo.SelectedIndex = 2
Me.ToolStripProgressBar1.Value = 75
Sold.SoldsDataBinding()
' populate combobox
Sold.sold1combo.DataSource = Me.BindingSource4
Sold.sold1combo.DisplayMember = "NewAddress"
Sold.sold1combo.ValueMember = "NewAddress"
Sold.sold1combo.SelectedIndex = 0
Me.ToolStripProgressBar1.Value = 80
Sold.sold2combo.DataSource = Me.BindingSource5
Sold.sold2combo.DisplayMember = "NewAddress"
Sold.sold2combo.ValueMember = "NewAddress"
Sold.sold2combo.SelectedIndex = 1
Me.ToolStripProgressBar1.Value = 85
Sold.sold3combo.DataSource = Me.BindingSource6
Sold.sold3combo.DisplayMember = "NewAddress"
Sold.sold3combo.ValueMember = "NewAddress"
Sold.sold3combo.SelectedIndex = 2
Me.ToolStripProgressBar1.Value = 100
formattrends()
Me.ToolStripProgressBar1.Visible = False
Me.ToolStripStatusLabel2.Visible = False
End Sub
This is how I go from Form2 (Listing) back to From1
Code:
Me.Hide()
Subject_Values.Show()
I think that is the problem, instead of Me.Hide I changed it to Me.Close
-
Oct 22nd, 2011, 09:59 PM
#10
Re: Clear Tables/Ctrls to open new File
Why hide the current form and show a new one when you can simply display a modal dialogue?
-
Oct 22nd, 2011, 10:39 PM
#11
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
Not knowing anything about Modal forms I cant answer that, but will research it. Reading your blog on default instances now
-
Oct 23rd, 2011, 12:34 AM
#12
Re: Clear Tables/Ctrls to open new File
You do know about modal dialogues because you use them all the time. Let's say that you are working in VS and you want to change an IDE option. You select Tools -> Options and what happens? Does the VS window disappear? Of course not. A dialogue is opened that prevents you accessing the main window until it is dismissed. No doubt you have used many such dialogues in many different applications. In .NET, all you have to do is call ShowDialog on a form to make it a modal dialogue. You can set any properties you like of that form beforehand to pass data in and then get any properties you like after it returns to get data out. Also, you would create a new dialogue each time so there's no need for clearing anything.
-
Oct 23rd, 2011, 10:37 PM
#13
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
Ok so I have 3 forms in my program total
Main Form which has two buttons one to view form 2 and one to view form 3
then each of those forms has buttons to view the other two
my question is would suggest I Showdialog() then hide the form that is open? or close?
-
Oct 23rd, 2011, 11:26 PM
#14
Re: Clear Tables/Ctrls to open new File
It's hard to know without a proper explanation of the purpose of each form but, most likely, you should have one main form and open each of the others only from that and each as a modal dialogue.
-
Oct 23rd, 2011, 11:39 PM
#15
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
The main form is where I open a file with textfieldparser etc... as described in initial post....
then second form displays 3 comboboxes and multiple TextBoxes that are bound to binding source created on main form
same for form 3
I have it setup now to leave main form open, then open either form 2 or 3 not sure whether to hide or close them, depending on the speed of user machine it can take a few seconds to load each form since they contain about 100 text boxes and perform initial calculations etc.... so I thought hiding would be better rather then closing
should i hide or close the form before i open the new
-
Oct 23rd, 2011, 11:55 PM
#16
Re: Clear Tables/Ctrls to open new File
If you're using ShowDialog then you should undoubtedly be closing. Frankly, I can't imagine a good UI having 100 TextBoxes directly on a form. That sounds like a possible job for a TabControl, which would also speed up the load time because the controls on each TabPage are not created until that TabPage is displayed.
-
Oct 24th, 2011, 01:11 AM
#17
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
My understanding of a tab page is that instead of displaying information across 3 seperate forms, It would be on one form but reside within 3 seperate tabs?
-
Oct 24th, 2011, 01:36 AM
#18
Re: Clear Tables/Ctrls to open new File
It's not really about taking information from multiple forms and combining it into one. It's more about taking information form one form and breaking it into groups, displaying only one group at a time to make it easier for the user to visualise and work with. All the controls still exist within one form, just as if they were all displayed at the same time, but the form can be less confusing to the user because there's less to take in at one time.
-
Oct 24th, 2011, 01:58 PM
#19
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
ok gotcha, while It may seem like 100 textboxes is confusing its actually the purpose of the program, user needs to analyze data side by side, so I have 3 cloumns of text boxes and 33 rows, works great
I like the idea of tab control instead of opening and closing 3 forms the user can just click a tab
-
Oct 24th, 2011, 08:38 PM
#20
Re: Clear Tables/Ctrls to open new File
 Originally Posted by billboy
I have 3 cloumns of text boxes and 33 rows
Sounds to me like you should be using a DataGridView, which would be much more efficient with regards to loading times and the like.
-
Oct 24th, 2011, 10:02 PM
#21
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
Do you know how to reverse the layout of a DataGridView?
In other words instead of
Col1 Col2 Col3
row1
row2
row3
I need to take a row and display its data vcertically
Row1
Col1
Col2
Col3
Then I still need boxes to have the calculations
So I have
Row1
Col calculation
Col calculation
and so forth
-
Oct 24th, 2011, 10:15 PM
#22
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
Last edited by billboy; Oct 24th, 2011 at 10:49 PM.
-
Oct 24th, 2011, 10:17 PM
#23
Re: Clear Tables/Ctrls to open new File
There's no such thing as a reversed layout. Rows are, by definition, horizontal and columns are, by definition, vertical. If you need a series of values to be displayed vertically then you put the values in the same column, each in a different row. It's up to you to put the data where you want it and, if you need to perform calculations using that data, it's up to you to write the appropriate code to perform those calculations. That's it, that's all.
-
Oct 24th, 2011, 10:24 PM
#24
Re: Clear Tables/Ctrls to open new File
With more information, I can see how that might be difficult to display in a grid. That said, I can see a lot of TextBoxes there that look like they should probably be Labels, which are more lightweight. Anyway, we seem to have drifted rather off-topic here, so I'll leave it at that.
-
Oct 24th, 2011, 10:48 PM
#25
Thread Starter
Frenzied Member
Re: Clear Tables/Ctrls to open new File
Yes we have drifted, thanks alot for the informative dialogue
It is MUCH appreciated
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
|