|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can You Save the DataGridView Sort Order / Update the Underlying DB?When I save datagridview record changes, should the current sort column and order save? I have a datagridview I placed onto a form, and it is "fed" without any sorting from a DB (bound datasource). Changes to any cell in the datagridview save just fine, but if the user sorts the datagridview by clicking on a column (as they like to do), that does not save/update the DB. (And does not persist from session to session.) Is this by design? If not, any suggstions as to what to verify or enable to make it work? If so, any suggestions as to how I might code around this? Users want sort to stay sorted, and some other parts of my app re-purpose the data, which should also appear in the sorted order. Thanks, Patrick Patrick A wrote:
> When I save datagridview record changes, should the current sort Only if you save the current sort column and order somewhere and then sort > column and order save? on that column automatically the next time a user retrieves that data. You may want to do thar on a per-user basis. The other parts of your app will have to use the saved sort column/order too. Data in a database are not inherently ordered in any way: {1,2,3,4} is the same as {2,3,1,4} in a database because it is set-based. It is only when you select data that you can choose an order for it. HTH, Andrew Thanks Andrew!
I can save it on a per user basis, so that's no problem. I like that it then becomes available elsewhere - I had not thought of that. I should also be able to save it to an ini file for use the next time the user opens the app, correct? (Just thinking out loud before breakfast.) Patrick Show quoteHide quote On Mar 26, 4:57 am, "Andrew Morton" <a***@in-press.co.uk.invalid> wrote: > Patrick A wrote: > > When I save datagridview record changes, should the current sort > > column and order save? > > Only if you save the current sort column and order somewhere and then sort > on that column automatically the next time a user retrieves that data. You > may want to do thar on a per-user basis. > > The other parts of your app will have to use the saved sort column/order > too. > > Data in a database are not inherently ordered in any way: {1,2,3,4} is the > same as {2,3,1,4} in a database because it is set-based. It is only when you > select data that you can choose an order for it. > > HTH, > > Andrew Patrick A wrote:
> I can save it on a per user basis, so that's no problem. Presumably the database is (physically) the same one for all the users, so > > I like that it then becomes available elsewhere - I had not thought of > that. > > I should also be able to save it to an ini file for use the next time > the user opens the app, correct? it may make more sense to save it there rather than locally. That way, if they log in (as themselves) on other computers, they will still have the same state even if they don't have roaming profiles. Andrew Andrew,
Actually, the DB is a different one for all users. (It's a 200K MDB file.) It is stored on their "H:" drive, a networked drive that maps as the same letter wherever they log in. But yes, I can write the value there or in the ini file, which is also stored on their "H:" drive. Show quoteHide quote storyOn Mar 26, 7:57 am, "Andrew Morton" <a***@in-press.co.uk.invalid> wrote: > Patrick A wrote: > > I can save it on a per user basis, so that's no problem. > > > I like that it then becomes available elsewhere - I had not thought of > > that. > > > I should also be able to save it to an ini file for use the next time > > the user opens the app, correct? > > Presumably the database is (physically) the same one for all the users, so > it may make more sense to save it there rather than locally. That way, if > they log in (as themselves) on other computers, they will still have the > same state even if they don't have roaming profiles. > > Andrew OK, I'm very close...but I'm getting poked in the eye by differing
types, and can't figure out how to convert 'System.String' to type 'System.Windows.Forms.DataGridViewColumn' 'My Declarations Public Class MyGlobals Public Shared TimersSortCol ' I have tried declaring this in several ways...Nothing works on both sides. Public Shared TimersSortOrd as String End Class 'Getting the Values 'Get the TBL_TimersDataGridView sort order from the ini file Dim strSortOrd As String = MyGlobals.oIniFile.GetString("General", "SortOrd", "0") MyGlobals.TimersSortOrd = strSortOrd 'returns a number 'Get the TBL_TimersDataGridView sort column from the ini file Dim strSortCol As String = MyGlobals.oIniFile.GetString("General", "SortCol", "0") MyGlobals.TimersSortCol = strSortCol 'returns a number 'Using the Values TBL_TimersDataGridView.Sort(MyGlobals.TimersSortCol, MyGlobals.TimersSortOrd) The error; Unable to cast object of type 'System.String' to type 'System.Windows.Forms.DataGridViewColumn'. Any suggestions? Thanks, Patrick Patrick A wrote:
> OK, I'm very close...but I'm getting poked in the eye by differing Without looking into it any depth, I can suggest iterating over the columns > types, and can't figure out how to convert > 'System.String' to type 'System.Windows.Forms.DataGridViewColumn' > > Any suggestions? and using the one which has a name which is the same as the stored value. There might be a more direct way. Something like: dim selectedCol as datagridviewcolumn for each dgvc as datagridviewcolumn in TBL_TimersDataGridView.Columns if dgvc.Name=whatever then selectedCol=dgvc exit for end if next Andrew Andrew,
Thanks for your reply, but I must be missing something - I'm not sure how that sorts my column. Can you provide a little more detail? Patrick Show quoteHide quote On Mar 29, 6:00 am, "Andrew Morton" <a***@in-press.co.uk.invalid> wrote: > Patrick A wrote: > > OK, I'm very close...but I'm getting poked in the eye by differing > > types, and can't figure out how to convert > > 'System.String' to type 'System.Windows.Forms.DataGridViewColumn' > > > Any suggestions? > > Without looking into it any depth, I can suggest iterating over the columns > and using the one which has a name which is the same as the stored value. > There might be a more direct way. > > Something like: > > dim selectedCol as datagridviewcolumn > for each dgvc as datagridviewcolumn in TBL_TimersDataGridView.Columns > if dgvc.Name=whatever then > selectedCol=dgvc > exit for > end if > next > > Andrew Patrick A wrote:
Show quoteHide quote > On Mar 29, 6:00 am, "Andrew Morton" N.b: where "whatever" would be "MyGlobals.TimersSortCol">> Patrick A wrote: >>> OK, I'm very close...but I'm getting poked in the eye by differing >>> types, and can't figure out how to convert >>> 'System.String' to type 'System.Windows.Forms.DataGridViewColumn' >> >>> Any suggestions? >> >> Without looking into it any depth, I can suggest iterating over the >> columns and using the one which has a name which is the same as the >> stored value. There might be a more direct way. >> >> Something like: >> >> dim selectedCol as datagridviewcolumn >> for each dgvc as datagridviewcolumn in TBL_TimersDataGridView.Columns >> if dgvc.Name=whatever then >> selectedCol=dgvc You see above where you needed a System.Windows.Forms.DataGridViewColumn >> exit for >> end if >> next >> > Thanks for your reply, but I must be missing something - I'm not sure > how that sorts my column. > > Can you provide a little more detail? (DGVC) to tell it what to sort on, and you were getting the error that it couldn't convert from "System.String"? Well, my idea was to find that particular DGVC given its name (the string). This part: > 'Using the Values Gave you the error> TBL_TimersDataGridView.Sort(MyGlobals.TimersSortCol, > MyGlobals.TimersSortOrd) > Unable to cast object of type 'System.String' to type because the first argument must be a DGVC.> 'System.Windows.Forms.DataGridViewColumn'. Does that fill in the gap I left? (The comments in your code "returns a number" are a bit unhelpful when it is actually returning a string.) Andrew
How to navigate through dataset
Acessing DLL members which differ only in Case from VB.net Minimise button on title bar and resize Reference to a DLL on the network Insert Record in DataContext without upgrading the database Context Menus combobox compiled on visual studio 2003 on windows XP, want to install on windows 7, error Can anyone recommend a print contol library please? Configure Properties of Windows User (Terminal Server Eviroment) |
|||||||||||||||||||||||