473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to reset Windows Application's default programmatically?

Hi Everyone,

I have made a windows application using vb.net 2003. When user opens this
application it will display a default location in a textbox. This
application has to allow user to change the default location and set their
desired location as application’s new default. For instance, if the
application’s default location is Chicago, every time user launches this
program Chicago will be displayed in the textbox. If user changes the
default location to Toronto, then click a button to set Toronto as default.
Later when user opens this application again, it should display Toronto
instead of Chicago. How can I achieve this? Please help.

Thank you in advance.

Nina
Sep 20 '06 #1
6 4398
Hey Nina,
You might want to use windows registry to do this.
Use SaveSetting() to store the setting into registry and GetSetting to
retreive it back.

Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
store after user selects a different city.

Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
"City", "DefaultValue") when you load the form to fill up the textbox

Hope it helps.

Sep 20 '06 #2
Another option is to use XML files. Check out the XML document object
model. Be warned that this approach is more difficult to set up and
requires more code to use. Just throwing in my 2 cents :-)

Thanks,

Seth Rowe

IdleBrain wrote:
Hey Nina,
You might want to use windows registry to do this.
Use SaveSetting() to store the setting into registry and GetSetting to
retreive it back.

Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
store after user selects a different city.

Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
"City", "DefaultValue") when you load the form to fill up the textbox

Hope it helps.
Sep 20 '06 #3
I agree with rowe_newsgroups, XML is how I would do it.

Using XML isn't hard either. I use the code below to do exactly this.

Private Sub LoadSettings()

Dim dsSettings as new Dataset
Dim dtSettings as Datatable
Dim SettingsPath As String = Application.StartupPath & "\" &
My.Settings.ServerSettingsFile

dsSettings.DataSetName = "ServerSettings"

If IO.File.Exists(SettingsPath) Then
dsSettings.ReadXml(SettingsPath)
dtSettings = dsSettings.Tables("HardDriveSettings")

Else

Dim dcSN As New DataColumn 'Server Name
Dim dcDTM As New DataColumn 'Drive to monitor.
Dim dcFSTH As New DataColumn 'Free Space Threshhold in GBs
Dim drSettings As DataRow

dcSN.ColumnName = "ServerName"
dcSN.DataType = GetType(System.String)
dcDTM.ColumnName = "DriveLeter"
dcDTM.DataType = GetType(System.String)
dcFSTH.ColumnName = "FreeSpaceThreshHold"
dcFSTH.DataType = GetType(System.Int32)

dtSettings = New DataTable
dtSettings.TableName = "HardDriveSettings"

dtSettings.Columns.Add(dcSN)
dtSettings.Columns.Add(dcDTM)
dtSettings.Columns.Add(dcFSTH)

drSettings = dtSettings.NewRow
drSettings(0) = "stc-dc"
drSettings(1) = "D:"
drSettings(2) = 15
dtSettings.Rows.Add(drSettings)

End If

End Sub

In the above example I created a settings file for a program which
monitors hard drive space on production servers. Using XML to store the
list of servers to be monitored along with the dirve letter and free
space setting.

In your case after you load the settings using dsSettings.ReadXml(Path)
and after your users make a change you would then call
dsSettings.WriteXml(Path) to write the change to disk.

Izzy

rowe_newsgroups wrote:
Another option is to use XML files. Check out the XML document object
model. Be warned that this approach is more difficult to set up and
requires more code to use. Just throwing in my 2 cents :-)

Thanks,

Seth Rowe

IdleBrain wrote:
Hey Nina,
You might want to use windows registry to do this.
Use SaveSetting() to store the setting into registry and GetSetting to
retreive it back.

Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
store after user selects a different city.

Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
"City", "DefaultValue") when you load the form to fill up the textbox

Hope it helps.
Sep 20 '06 #4
I agree with rowe_newsgroups, XML is how I would do it.

Using XML isn't hard either. I use the code below to do exactly this.

Private Sub LoadSettings()

Dim dsSettings as new Dataset
Dim dtSettings as Datatable
Dim SettingsPath As String = Application.StartupPath & "\" &
My.Settings.ServerSettingsFile

dsSettings.DataSetName = "ServerSettings"

If IO.File.Exists(SettingsPath) Then
dsSettings.ReadXml(SettingsPath)
dtSettings = dsSettings.Tables("HardDriveSettings")

Else

Dim dcSN As New DataColumn 'Server Name
Dim dcDTM As New DataColumn 'Drive to monitor.
Dim dcFSTH As New DataColumn 'Free Space Threshhold in GBs
Dim drSettings As DataRow

dcSN.ColumnName = "ServerName"
dcSN.DataType = GetType(System.String)
dcDTM.ColumnName = "DriveLeter"
dcDTM.DataType = GetType(System.String)
dcFSTH.ColumnName = "FreeSpaceThreshHold"
dcFSTH.DataType = GetType(System.Int32)

dtSettings = New DataTable
dtSettings.TableName = "HardDriveSettings"

dtSettings.Columns.Add(dcSN)
dtSettings.Columns.Add(dcDTM)
dtSettings.Columns.Add(dcFSTH)

drSettings = dtSettings.NewRow
drSettings(0) = "stc-dc"
drSettings(1) = "D:"
drSettings(2) = 15
dtSettings.Rows.Add(drSettings)

End If

End Sub

In the above example I created a settings file for a program which
monitors hard drive space on production servers. Using XML to store the
list of servers to be monitored along with the dirve letter and free
space setting.

In your case after you load the settings using dsSettings.ReadXml(Path)
and after your users make a change you would then call
dsSettings.WriteXml(Path) to write the change to disk.

Izzy

rowe_newsgroups wrote:
Another option is to use XML files. Check out the XML document object
model. Be warned that this approach is more difficult to set up and
requires more code to use. Just throwing in my 2 cents :-)

Thanks,

Seth Rowe

IdleBrain wrote:
Hey Nina,
You might want to use windows registry to do this.
Use SaveSetting() to store the setting into registry and GetSetting to
retreive it back.

Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
store after user selects a different city.

Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
"City", "DefaultValue") when you load the form to fill up the textbox

Hope it helps.
Sep 20 '06 #5
Thank you IdleBrain, rowe_newsgroups, and Izzy for all your help. Now I know
where to start. Have a nice day!

Nina

"Izzy" wrote:
I agree with rowe_newsgroups, XML is how I would do it.

Using XML isn't hard either. I use the code below to do exactly this.

Private Sub LoadSettings()

Dim dsSettings as new Dataset
Dim dtSettings as Datatable
Dim SettingsPath As String = Application.StartupPath & "\" &
My.Settings.ServerSettingsFile

dsSettings.DataSetName = "ServerSettings"

If IO.File.Exists(SettingsPath) Then
dsSettings.ReadXml(SettingsPath)
dtSettings = dsSettings.Tables("HardDriveSettings")

Else

Dim dcSN As New DataColumn 'Server Name
Dim dcDTM As New DataColumn 'Drive to monitor.
Dim dcFSTH As New DataColumn 'Free Space Threshhold in GBs
Dim drSettings As DataRow

dcSN.ColumnName = "ServerName"
dcSN.DataType = GetType(System.String)
dcDTM.ColumnName = "DriveLeter"
dcDTM.DataType = GetType(System.String)
dcFSTH.ColumnName = "FreeSpaceThreshHold"
dcFSTH.DataType = GetType(System.Int32)

dtSettings = New DataTable
dtSettings.TableName = "HardDriveSettings"

dtSettings.Columns.Add(dcSN)
dtSettings.Columns.Add(dcDTM)
dtSettings.Columns.Add(dcFSTH)

drSettings = dtSettings.NewRow
drSettings(0) = "stc-dc"
drSettings(1) = "D:"
drSettings(2) = 15
dtSettings.Rows.Add(drSettings)

End If

End Sub

In the above example I created a settings file for a program which
monitors hard drive space on production servers. Using XML to store the
list of servers to be monitored along with the dirve letter and free
space setting.

In your case after you load the settings using dsSettings.ReadXml(Path)
and after your users make a change you would then call
dsSettings.WriteXml(Path) to write the change to disk.

Izzy

rowe_newsgroups wrote:
Another option is to use XML files. Check out the XML document object
model. Be warned that this approach is more difficult to set up and
requires more code to use. Just throwing in my 2 cents :-)

Thanks,

Seth Rowe

IdleBrain wrote:
Hey Nina,
You might want to use windows registry to do this.
Use SaveSetting() to store the setting into registry and GetSetting to
retreive it back.
>
Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
store after user selects a different city.
>
Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
"City", "DefaultValue") when you load the form to fill up the textbox
>
Hope it helps.

Sep 21 '06 #6
Hello Izzy,

I don't like this approach. Datasets dont feel right for storing application
settings. A custom object would be a better approach. It feels better.
It also allows your settings to take advantage of strongly typed data, and
intellisense within the IDE.

-Boo
I agree with rowe_newsgroups, XML is how I would do it.

Using XML isn't hard either. I use the code below to do exactly this.

Private Sub LoadSettings()

Dim dsSettings as new Dataset
Dim dtSettings as Datatable
Dim SettingsPath As String = Application.StartupPath & "\" &
My.Settings.ServerSettingsFile
dsSettings.DataSetName = "ServerSettings"

If IO.File.Exists(SettingsPath) Then
dsSettings.ReadXml(SettingsPath)
dtSettings = dsSettings.Tables("HardDriveSettings")
Else

Dim dcSN As New DataColumn 'Server Name
Dim dcDTM As New DataColumn 'Drive to monitor.
Dim dcFSTH As New DataColumn 'Free Space Threshhold in GBs
Dim drSettings As DataRow
dcSN.ColumnName = "ServerName"
dcSN.DataType = GetType(System.String)
dcDTM.ColumnName = "DriveLeter"
dcDTM.DataType = GetType(System.String)
dcFSTH.ColumnName = "FreeSpaceThreshHold"
dcFSTH.DataType = GetType(System.Int32)
dtSettings = New DataTable
dtSettings.TableName = "HardDriveSettings"
dtSettings.Columns.Add(dcSN)
dtSettings.Columns.Add(dcDTM)
dtSettings.Columns.Add(dcFSTH)
drSettings = dtSettings.NewRow
drSettings(0) = "stc-dc"
drSettings(1) = "D:"
drSettings(2) = 15
dtSettings.Rows.Add(drSettings)
End If

End Sub

In the above example I created a settings file for a program which
monitors hard drive space on production servers. Using XML to store
the list of servers to be monitored along with the dirve letter and
free space setting.

In your case after you load the settings using
dsSettings.ReadXml(Path) and after your users make a change you would
then call dsSettings.WriteXml(Path) to write the change to disk.

Izzy

rowe_newsgroups wrote:
>Another option is to use XML files. Check out the XML document
object model. Be warned that this approach is more difficult to set
up and requires more code to use. Just throwing in my 2 cents :-)

Thanks,

Seth Rowe

IdleBrain wrote:
>>Hey Nina,
You might want to use windows registry to do this.
Use SaveSetting() to store the setting into registry and GetSetting
to
retreive it back.
Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago")
to store after user selects a different city.

Use txtboxCityName.text = GetSetting("ApplicationName",
"FolderName", "City", "DefaultValue") when you load the form to fill
up the textbox

Hope it helps.

Sep 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Charles M. Fish, Sr. | last post by:
I’m so tired from banging this problem around all day, I hope I can explain it succinctly & accurately. I want to execute a function immediately following a click on <input type="RESET"... ...
9
by: Hardy Wang | last post by:
Hi all: I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based ont the code...
1
by: Silverton Mike | last post by:
I need to retrieve Windows Media Player playlists programmatically via C# from a desktop machine. Does WMP keep track of used/created playlists via registry entries or a saved file on the hard...
16
by: Marina | last post by:
Hi, I am trying to find the minimum security settings to allow a windows control embedded in IE have full trust. If I give the entire Intranet zone full trust, this works. However, this is...
2
by: Lance | last post by:
I want to be able to reset a complex property in a PropertyGrid. I know that for properties that are ValueTypes you can include System.ComponentModel.DefaultValue in the declaration of the property....
6
by: PiotrKolodziej | last post by:
Hi When my application is on, i can't reset or power off computer. Every program closes but this one.... Why this happens? PK
16
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm looking for a way to programmatically retrieve the following if possible: Windows Installation Key or COA from the registry Windows installed...
8
by: TomC | last post by:
I want to bypass the Windows Form Designer in VS, to create a form programmatically. The elements of the form are to be arranged in a table, and I want the size of the table (and therefore the...
16
by: Giovanni D'Ascola | last post by:
Hi. I noticed that <input type="reset"actually don't enable checkbutton which are checked by default after they have been disabled by javascript. It's a bug?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.