In trouble.....

  • Thread starter Thread starter scorpion53061
  • Start date Start date
S

scorpion53061

Well as some of you know I was using a tab control for a project I was
building for my boss.

Today he tells me that he wants:

When he switches tabs to be able to switch back and see whatever it was he
was doing on the other tab.

That may not sound like a big thing but I used the same controls for each
tab and then manually cleared the page so he didnt see the same in another
page. (datasource cleared out etc)

This is what I did:

If TabControl1.SelectedIndex = 2 Then
DataGrid1.DataSource = Nothing
DataGrid2.DataSource = Nothing
Label2.Text = ""
Label18.Text = ""
'actions to fill them wiht new values
End If
If TabControl1.SelectedIndex = 1 Then
DataGrid1.DataSource = Nothing
DataGrid2.DataSource = Nothing
Label2.Text = ""
Label18.Text = ""
'actions to fill them with new values
End If

I have to clear it on their arrival other wise they will see the data from
the other page, right?

Is there any way I can retain what they did without being forced to create
different controls on each tab page?
 
Scorpion,

What is the big deal with having two more grids or you could cache the
datasource

Dan
 
if i recall corectly he's talking about a lot of tabpages
i do have a suggestion let us know how it turns out
create a class that holds all the data of 1 tabpage and an integer to tell w
tabpage we are talking about (even better put them in an array, creating
class arrays has been talked about a while back)
it could have some datasets, strings, ...
put the code to manipulate the data in the class
when the user selects a tabpage populate it from the class, if it's a new
one it would be blank or you get it from the db, if it's already filled in
populate it from the class.

hope it helps

eric
 
Hi Eric,

I was thinking about that solution you told also, but than I did look to the
answer/question from Solex and thought, yes Solex is right, why would
Scorpion just use one datagrid, while more will maybe fix his problem very
simple.

What are your arguments not doing that, I really was in doubt if I would
give the same answer as you?

Cor
 
if i'm not mistaking he has 28 tabpages that use this (again if im not
mistaking there could be more in the future)
i thought he wanted something that would work for 3, 10, 28,100, ...
tabpages and do'nt give to much work for an additional page.

imagine if you have to change something in your code, do you want to do it
once or a 100 times?

an alternative would be creating a control array, but since he seems to have
something working now it seemed bether to expand on that.

eric
 
Hi EricJ,

I understand now, but thinking on it I think I would do it by making a user
control and put that in an array then ( I never did, but I would try it
first if it was my problem)

:-)

Thanks,

Cor
 
Hi eric you are correct. This had 28 tab pages.

The only way I could see this working was to make duplicate controls for all
the tab pages.

Now on your suggestion you I am sorry to ask this but would you take a
control such as a datagrid (I also have to do this with several other types
of controls) and show me how you would do this? Just enough to help get me
started on what you are describing.
 
I have something that worked here........it is so simple I may not be
thinking of someting but here goes.....

I declared at the module level 28 different dataviews - one for each tab
page datagrid.

When the user selects that tab page it binds to that view.

The data is there when it is supposed to be and not there when it is not
supposed ot be. It also retained the formatting I call for in code. The only
downside is when there were zero rows it showed a datagrid with one square
in teh left hand corner for the grid but I think I can get away with that.

My concern is obviously what effect 28 dataviews will have on the users
resources, and down the road when I need to update the views when the user
is not looking at the tab page if it will be difficult to do.

I assume adding or removing a row from a view is not that hard. At least I
hope.

What do you guys think?
 
this is roughly w i had in mind (ok you will still have a lot of dataviews
but i doubt that will be a problem, its a lot better then accessing the db
all the time).
use the property's of the class in your application
\\
'first a class
Public Class test
Private dv As DataView
Private str1, str2 As String
Public Sub New()
dv = New DataView
str1 = ""
str2 = ""
End Sub
Public Sub New(ByVal dview As DataView, ByVal string1 As String, ByVal
string2 As String)
dv = dview
str1 = string1
str2 = string2
End Sub
Public Property dView() As DataView
Get
Return dv
End Get
Set(ByVal Value As DataView)
dv = Value
End Set
End Property
Public Property String1() As String
Get
Return str1
End Get
Set(ByVal Value As String)
str1 = Value
End Set
End Property
'...
Public Sub load()
'load the data from your db here
End Sub
Public Sub save()
'save the data in the db here
End Sub
'...
End Class
//

in your app create an array of the class

\\
private arrtest(28) as test
//

when you use it for the first time

\\
arrtest(i) = new test
'i would be the index of the tab page
//

then fill the controls w the class
 
scor,

Obviously I am coming into this a little late, but if you expect this
particular part of the project to continue to grow (i.e. increasing the
number of tabs as time goes on) might I suggest you change your UI design.

I am not familar with the domain problem you are trying to solve but I
cannot imagine that a window with 28+ tabs is going to be particuarly easy
to use. Perhaps a menuing system or treeview will help with navigating to
the particular pages and only load what is necessary upon the users request

To answer your question I think that the approach of having multiple
datagrids and refreshing the datasource when the user clicks on the
approprate tab (and clearing the datasource when the tab has lost focus) is
probably your best bet if you cannot change your GUI.

This way you know that the amount of memory used will grow at resonable
rate. Esentially then number of datagrids times the amount of memory used
per datagrids + the size of the current dataview. If you cache the
dataviews then your memory usage will eventually (if not already) surpass
the above senario as the dataviews increase in size.

Good Luck!
Dan
 
The way this was working was that whenever a tab was clicked it was told to
add the same set of controls to the page. (2 datagrids, 8 labels, six
buttons)

Do you think that as each tab page is clicked that the framework will
iniitiate garbage collection as needed or do I need to manually somehow
dispose of the controls to keep them from bombing the resources on the
computer?

As far as why the tab control was chosen that was the bosses choice. IT
certainly was not mine. I have not cared for the trouble this particular
control has caused me. Granted, my inexperience with the control has been a
factor, but there are some bugs with this control that make life
interesting.

I don't want to clear the datasource when teh leave the tab page otherwise
the user when they return will not see what they had done when they were
there previously. My concern is how to keep the various dataviews updated if
things they do on other tab pages affect what result they should be viewing.
Using the same datagrid presented binding problems but what I did was create
a dataview for each screen's grid and told to bind to that dataview when
they returned.

Thanks much for your thoughts. If you have more I would love to hear them.
 
Let me reiterate to make sure I understand your requirements

(1) the dataviews you have are based on a datatable.
(2) there are 28+ dataviews that you need to maintain their state as they
are changed by the user
(3) if a dataview is changed in a way the updates the underlying datatable
you do NOT want the other dataviews to be updated.
(4) persumably you want the user to have the ability to view all of thier
changes before they commit the entire set of changes to the underlying
datatable.

Is this correct?

Dan
 
Hi Scorpion,

I am curious also and I take the text from Solex

1) the dataviews you have are based on a datatable.

Is every dataview also one datatable or are all dataviews, views on the same
datatable (as part of a dataset or more datasets)?

Cor
 
Each has their own dataset and can be updated (row delete, modify, add)
independantly.

What I want to do is in some cases but not all changes in one dataview may
need to be reflected in another dataview.
 
1 the dataviews are based on several tables. Each dataset has its own
dataview the way it is currently set up. Each dataset is copied to another
dataset called dscopy so that formatting rules and such can be applied
without having to write 28 formatting procedures.

2-3. Yes I need to maintaint their state but I also need to be able to
adjust it. For example if an item is added ot the order the order dataview
would need to be addressed so that when they returned to that screen the
item would show as being there.

4. Would be a very nice addition. DO not currently have it in place however.
Open to anyting here.

I hope I am clear. It is confusing I know.
 
scor.,

Based on your comments, I am not really sure what would be the problem in
updating the underlying datasets as changes to the data is made. For
instance consider the following sequences

User makes changes to Page N
System updates underlying dataset as a result of the changes
System updates underlying dataset(s) for any dependent tables
System refreshes current Page

User selects new Page
System recreates underlying dataset for New Page
System recreate undelying dataview and rebinds

Obviously your application is getting compilcated and based on my
experience and from what I can gather from your descriptions, I would start
thinking about creating an object model that houses both the data and the
interactions between the objects and ditch the DataTable/DataView
assemblies.

IMHO the DataTable and DataViews /Binding will only get you so far and then
you hit a brick wall. I'm sure that there are work arounds and neat tricks
to get things to work but at what point do you say to yourself that the code
you have created is too complicated and too difficult to modify if you need
to add a new feature such as item (4) in my previous post.

Dan
 
Hi Scorpion,

I was busy with something to investigate for Elena when I got this idea.

It is very quick and very dirty, but maybe it gives you some ideas

Cor
\\\\
Private dts(28) As DataTable
Private tabpages(28) As TabPage
Private dvs(28) As DataView
Private Sub DataForm1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Tabcontrol1 As New System.Windows.Forms.TabControl
Tabcontrol1.SuspendLayout()
Tabcontrol1.Dock = System.Windows.Forms.DockStyle.Fill
Tabcontrol1.Location = New System.Drawing.Point(0, 0)
Tabcontrol1.Name = "TabControl1"
Tabcontrol1.SelectedIndex = 0
Tabcontrol1.Size = New System.Drawing.Size(392, 216)
Tabcontrol1.TabIndex = 0
Me.Controls.Add(Tabcontrol1)
For i As Integer = 0 To 27
makedatatable(i)
tabpages(i) = settabpage(i, dts(i))
Tabcontrol1.Controls.Add(tabpages(i))
Next
End Sub
Private Sub makedatatable(ByVal number As Integer)
dts(number) = New DataTable("Action")
dts(number).Columns.Add(New DataColumn("Item", _
Type.GetType("System.Int32")))
dts(number).Columns.Add(New DataColumn("Alfa", _
Type.GetType("System.String")))
For i As Integer = 0 To 10
Dim dr As DataRow = dts(number).NewRow
dr("Item") = i * number
dr("Alfa") = (i * number).ToString
dts(number).Rows.Add(dr)
Next
dvs(number) = New DataView(dts(number))
End Sub

Public Function settabpage(ByVal number As Integer, _
ByVal datatable As DataTable) As TabPage
Dim TabPage2 As New System.Windows.Forms.TabPage
TabPage2.Text = number.ToString
TabPage2.Dock = DockStyle.Fill
Dim datagrid2 As New System.Windows.Forms.DataGrid
datagrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText
datagrid2.DataSource = dvs(number)
datagrid2.AllowSorting = True
datagrid2.ReadOnly = False
datagrid2.Dock = DockStyle.Fill
Dim dgts As DataGridTableStyle = New DataGridTableStyle
dgts.MappingName = "Action"
dgts.GridColumnStyles.Add(New DataGridTextBoxColumn)
dgts.GridColumnStyles.Item(0).MappingName() = "item"
dgts.GridColumnStyles.Item(0).HeaderText = "Action"
datagrid2.TableStyles.Clear()
datagrid2.TableStyles.Add(dgts)
datagrid2.Refresh()
datagrid2.Visible = True
datagrid2.ColumnHeadersVisible = True
TabPage2.Controls.Add(datagrid2)
Return TabPage2
End Function
////
 
Back
Top