Registery help

A

AliR \(VC++ MVP\)

Hi everyone,

I'm trying to read and write a value from the registry. My write routine
works fine, after it runs I can see the item in the registry.
But when I read it back I keep getting a 1 back.

Here is the code:

Write to registry:
RegistryKey key =
Registry.CurrentUser.OpenSubKey("software\\LearnStar A+ TurningPoint XR
Client",true);
if (key == null)
{
key = Registry.CurrentUser.CreateSubKey("software\\LearnStar
A+ TurningPoint XR Client");
}
key.SetValue("Channel",channelCtrl.Value,RegistryValueKind.DWord);

Read from it:
RegistryKey key =
Registry.CurrentUser.OpenSubKey("software\\LearnStar A+ TurningPoint XR
Client");
int channel =
(int)key.GetValue("Channel",10,RegistryValueOptions.None);
channelCtrl.Value = channel;

channelCtrl is a NumericUpDown control

Thanks
AliR.
 
A

AliR \(VC++ MVP\)

Found the problem. The problem was that my write to registry code is in the
ValueChanged handler of the NumericUpDown control, and I was setting the
Minimum and Maximum before setting the value, there for the handler would
get called with the minimum value and that would get written to the
registry, and then I would read from the registry and assign the value.
Reversed the order and now it works fine. (except that when I set the value
to the control, it calls the value changed handler which writes the same
value back into the registry, not a big deal, but kinda of annoying)

AliR.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top