[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SAVE AND RESTORE LAYOUT OF DATAGRIDVIEW

Posted on 2012-09-10
23
Medium Priority
?
1,045 Views
Last Modified: 2012-09-19
Hi All,

I want let user to layout the default datagridview layout.
I want to save the layout change by user and to restore every time the user visit it.

Means every user have their own layout.

How could I do it ? I know there are several ways to save it, to (text, xml and etc) file, application setting, database and etc.

Thank you.
0
Comment
Question by:emi_sastra
  • 14
  • 9
23 Comments
 
LVL 1

Author Comment

by:emi_sastra
ID: 38382928
I know there are several ways to save it, to (text, xml and etc) file, application setting, database and etc.

Which one is the best ? But I don't know yet how to save and restore it.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38383185
I try below code and after I quit the application I don't see data at the setting ?

  Private Sub Form_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        If My.Settings.ColumnOrders1 Is Nothing Then
            My.Settings.ColumnOrders1 = New System.Collections.Specialized.StringCollection
            My.Settings.ColumnWidth1 = New System.Collections.Specialized.StringCollection
        End If

        My.Settings.ColumnOrders1.Clear()
        My.Settings.ColumnWidth1.Clear()

        For Each dc As DataGridViewColumn In dgvData.Columns
            My.Settings.ColumnOrders1.Add(dc.DisplayIndex.ToString())
            My.Settings.ColumnWidth1.Add(dc.Width.ToString())
        Next

        My.Settings.Save()
    End Sub

What's the problem ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38387720
Did you try using Closing event instead of Closed event? Is code executing fine if you step through it?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:emi_sastra
ID: 38389245
- Did you try using Closing event instead of Closed event?
No, I will try it now.

- Is code executing fine if you step through it?
No exception.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38389265
I provide exception, but there is no exception.

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38390231
So closing event did not help? Does it save if you use some plain string setting?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38391444
- So closing event did not help?
No.

- Does it save if you use some plain string setting?
What makes it different ?

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38391520
I have no idea how to code it if change to string from collection to string type.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38391536
I try below and still get nothing at project setting.

   Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        Try

            If My.Settings.ColumnOrders1 Is Nothing Then
                My.Settings.ColumnOrders1 = ""
                My.Settings.ColumnWidth1 = ""
            End If

            My.Settings.ColumnOrders1 = ""
            My.Settings.ColumnWidth1 = ""

            For Each dc As DataGridViewColumn In dgvData.Columns
                My.Settings.ColumnOrders1 = dc.DisplayIndex.ToString()
                My.Settings.ColumnWidth1 = dc.Width.ToString()
                Exit For
            Next

            My.Settings.Save()

        Catch ex As Exception

        End Try
       
    End Sub

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38395219
Are you looking at the right file? Debug vs Release folder.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38395243
- Are you looking at the right file? Debug vs Release folder.
I see it at project properties at setting menu, am I wrong ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38395621
Try checking the projectname.exe.config file
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38397185
Below are the setting :

<userSettings>
        <ERVSoftware.My.MySettings>
            <setting name="ColumnOrders1" serializeAs="String">
                <value />
            </setting>
            <setting name="ColumnWidth1" serializeAs="String">
                <value />
            </setting>
        </ERVSoftware.My.MySettings>
    </userSettings>

No value there ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38399386
My bad. User settings are stored in user profile folder. At application load, try reading that setting and use msgbox to see its value.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38400891
- User settings are stored in user profile folder.
Where is it ?

- At application load, try reading that setting and use msgbox to see its value.
How to read it ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38401779
Use

msgbox(My.Settings.settingname)
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38401791
Return 0

Would you please provide sample that works ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38402176
All my samples work. I just add a user level setting in my project properties and then I can just modify these at runtime without any problem. Does it work on a button click?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38409749
I am sorry just back.

Weird, still can not solve the problem.

I will ask for several questions regarding this topics.

1. What is the best media to save (xml, config file) to save layout when its size could become huge, since it allow user to change it independenttly, every user has their own style of grid. Should separate file for each form or grid.

2. For the purpose of point 1, what should be saved to file.

Hope you can help for this.

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38411209
Config files are xml files so its same thing. Each user has its own file. If its just the width and order of columns then you can just store a string like

columnname:width:order|columnname:width:order|...
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38411881
- Config files are xml files so its same thing.
Could we create more than one config files ?
Using xml we can create as many as we wish based on the form name.

-  If its just the width and order of columns then you can just store a string like
Since user could change the style : header columns height, columns width, columns shown, columns order, datetime format, number format.

Thank you.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 38415169
You can create xml files or plain text files. Better still, add settings to DataTable and then use WriteXML so you can readXML later to get the datatable back.
0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 38415546
Ok.

Thank you very much for your help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question