|
I have a listbox on a form that displays data from a registry key of value multistring. This listbox is filled when the form loads by this code:
RegistryKey getItems = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\RegKey_test");
if (getItems.GetValue("Items") != null)
{
string[] itemName = (string[])getItems.GetValue("Items");
for (int i = 0; i < itemName.Length; i++)
{
listBox1.Items.Add(getItems.GetValue("Items", itemName));
}
}
This works fine. But when I want to set the listbox items to the registry with the following code, an error occurs:
if (getItems.GetValue("Items") != null)
{ Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\RegKey_test", "Items", listBox1.Items.ToString(), RegistryValueKind.MultiString); }
I no that something is wrong with this line of code but I am not sure what it is. Can anyone advise me where I am going wrong please?
Lucy
|
|
|
|
|
What error are you getting? Is it an exception? What I don't like is
listBox1.Items.ToString() as listBox1.Items returns ObjectCollection and when you convert it to string you will get name of the type and not the items of listbox.
|
|
|
|
|
I didnt think that part was right. The error it returns is:
The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted.
If I just leave it as listBox1.Items the same error occurs.
|
|
|
|
|
I guess you are getting ArgumentException aren't you?
According to MSDN: "If the type of the specified value does not match the specified valueKind, and the data cannot be converted, ArgumentException is thrown"
If you have a look at definition of RegistryValueKind.MultiString it says: "Specifies an array of null-terminated strings, terminated by two null characters. This value is equivalent to the Win32 API registry data type REG_MULTI_SZ." In reality listbox.Items.ToString() retuns just a string while listbox.Items retuns ObjectCollection which is incompatible too. That's why you are getting the exception.
What are you trying to achieve?
|
|
|
|
|
Yes I am getting an ArgumentException.
I have a form with a listbox. When the form loads, each string in the multistring registry key is put into the listbox as an item. The user can then edit these items as well as removing and adding items. The items then need to be set as values back in the multistring registry key by the click of a button. Does that make sense?
|
|
|
|
|
Lucy_H85 wrote: Does that make sense?
Yes it does. Don't be rude. As I have already written RegistryValueKind.MultiString needs an array of strings. What you are passing is collection of objects. In my opinion you should create an array of string which will contain items from listbox and pass it to SetValue. Hope it helps
|
|
|
|
|
Appologies if I sounded rude but I was not being rude at all. I am not very good at explaining things sometimes so I was genuinly asking if my description was confusing or not.
Thanks for your comments I will try it out now.
Lucy
|
|
|
|
|
Lucy_H85 wrote: Appologies if I sounded rude but I was not being rude at all.
It's ok Please right back if you are still experiencing problems.
|
|
|
|
|
I'm working in C#.Net 2005.
I want to know that is there any solution to set File System Watcher on multi folders???
I'm waiting for quick reply...
Thanx in advance.
Rakesh
|
|
|
|
|
You can include have filesystemwatcher that looks at a directory and its subdirectories. If you need for different directories, then you will need several filesystemwatchers.
|
|
|
|
|
Thankx for your reply.
Is there any other way for multi folder watcher except add as many fileSystemWatcher as many folders that I want set watcher???
Rakesh
|
|
|
|
|
|
Thankx.
But if it is possible than please inform me.
Rakesh
|
|
|
|
|
I am developing a Outlook Shared add-in application using C#.net vs2005.
Here I save some user settings to the user.config file.
The settings are saved.
It is saving in the folder:
C:\Documents and Settings\<user name="">\Local Settings\Application Data\Microsoft_Corporation\<application name="">\10.0.2576
But I want to Store the user.config file in the Location that I Specify.
How can I do this?
I am trying to write a Custom Setting class but even I can’t do this!!!!!
Can this be done?
Is there any link tutor or any resource for this?
Awaiting reply,
Thanks in advance,
SrinivasanPrabakaran
|
|
|
|
|
|
I've made an inherited ListView control with a customized ColumnHeader Type.
I've overwritten the Columns property with a collection of my custom
ColumnHeader items. Now I would like to implement serialization so that
columns are persisted from designtime to runtime. But I cannot get it to
work.
I think it's because I don't know how to implement the type converter
correctly. Here's my suggestion for the type converter. Sample code for the
ListView, ColumnHeaderCollection and ColumnHeaderItem is supplied below. Can
anybody tell me what's wrong?
I've got a small test project (C# 2005) that I've stripped of everything but
the important part (the collection) - I cannot get the serialization to
work. I add columns at designtime, but no matter what, the columns are not
persisted to runtime. If anybody has got the time to help me, I can mail the
test project. I would REALLY appreciate any help I can get.
Cheers, Johnny J.
public class MyListViewColumnConverter : TypeConverter
{
public override bool CanConvertTo
(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo
culture, object value, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor) && value is
MyListViewColumn)
{
MyListViewColumnitem = (MyListViewColumn)value;
ConstructorInfo ci = typeof(MyListViewColumn).GetConstructor(new Type[]
{ });
if (ci != null)
{
return new InstanceDescriptor(ci, null, false);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
**********************************************************
Listview, ColumnheaderCollection, ColumnHeaderItem code:
namespace MyListView
{
public class MyListView : ListView
{
private MyColumnHeaderCollection myListViewColumnHeaders = null;
public MyListView()
{
myListViewColumnHeaders = new MyColumnHeaderCollection(this);
//Other Code
}
public MyListView(IContainer container)
{
myListViewColumnHeaders = new MyColumnHeaderCollection(this);
container.Add(this);
//Other Code
}
[Localizable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[MergableProperty(false)]
public new MyColumnHeaderCollection Columns
{
get { return myListViewColumnHeaders; }
}
//Other Code
}
[DesignTimeVisible(false)]
public class MyColumnHeaderCollection : ListView.ColumnHeaderCollection
{
private SortedList columnList = new SortedList();
public new MyListViewColumn this[int index]
{
get
{ return (MyListViewColumn)columnList.GetByIndex(index); }
}
public override ColumnHeader Add(string str, int width, HorizontalAlignment
textAlign)
{
MyListViewColumn column = new MyListViewColumn(str, width, textAlign);
this.Add(column);
return column;
}
public override int Add(ColumnHeader column)
{
return this.Add(new MyListViewColumn(column));
}
public override void AddRange(ColumnHeader[] values)
{
for (int index = 0; index < values.Length; index++)
{
this.Add(new MyListViewColumn(values[index]));
}
}
public int Add(MyListViewColumn column)
{
int retValue = base.Add(column);
columnList.Add(column.ColumnID, column);
return retValue;
}
public new void Remove(ColumnHeader column)
{
base.Remove(column);
columnList.Remove(((MyListViewColumn)column).ColumnID);
}
public new void RemoveAt(int index)
{
ColumnHeader column = this[index];
this.Remove(column);
}
public new void Clear()
{
base.Clear();
columnList.Clear();
}
}
[DesignTimeVisible(false)]
[TypeConverter(typeof(MyListViewColumnConverter))]
public class MyListViewColumn : ColumnHeader
{
private int m_ColumnID = 0;
private static int autoColumnID = 0;
public MyListViewColumn()
{
Initialize("", 60, HorizontalAlignment.Left);
}
public MyListViewColumn(string str, int width, HorizontalAlignment
textAlign)
{
Initialize(str, width, textAlign);
}
public MyListViewColumn(ColumnHeader column)
{
Initialize(column.Text, column.Width, column.TextAlign);
}
private void Initialize(string str, int width, HorizontalAlignment
textAlign)
{
base.Text = str;
base.Width = width;
base.TextAlign = textAlign;
m_ColumnID = autoColumnID++;
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int ColumnID
{
get { return m_ColumnID; }
}
}
}
|
|
|
|
|
i have a .net(C# + asp.net) web application that needs to show a set of log files on the browser once the user is logged in. The user should be able to download the files by clicking or right click->save as.
any ideas or samples will be thankful.
|
|
|
|
|
Here's[^] a sample that shows you how to do this.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
thanks for the reply.
I think the sample you mentioned will directly downlaod all the files without any selection.
i want the user to click a file and then download.
|
|
|
|
|
thanks for the reply.
I think the sample you mentioned will directly downlaod all the files without any selection.
i want the user to click a file and then download.
i mean i want the files names as a kind of links on the web page.
|
|
|
|
|
To do this, you need to build the list of links yourself, and dynamically attach an event handler which handles it in the same way that the button click does in the article.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I want to insert 2 rows into my spreadsheet but I have a dataset that is inserting values into the spreadsheet and I want to insert the rows after that values from my dataset.please help thanks.
|
|
|
|
|
how to loop the label or textid in C#.net
as per vb
textboxname.text=cmd.executescalar()
but it,s not working in c#.net
anyone tell me the suggestion now
lucky
|
|
|
|
|
Lucky Sheikh wrote: how to loop the label or textid in C#.net
as per vb
textboxname.text=cmd.executescalar()
but it,s not working in c#.net
anyone tell me the suggestion now
What do you mean "loop the label or textid"?
The code you have written puts the value of the first column of the first row in the Text property of the text box. It won't loop over anything.
|
|
|
|
|
textboxname.text=cmd.executescalar()
ExecuteScalar returns object.
You assigned this object to var string so that u r getting error here
try this code
textboxname.text=cmd.executescalar().ToString();
Best Regard
Pathan
---------------------------------------------------
|
|
|
|