Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm looking for a good example how to get values from a list with parameters, from one listbox to the other (see picture. I have a working code but saving the custom settings isn't working. I first tried it with a simple list (replace it later with parameter list) to test but you get an error because of the Properties.Settings.Default part.
Does anybody has an example or link to a site how to do this in Revit? I know it's more a C# question. But i searched a lot and no working solution found yet. To make it a little bit clearer i'm looking for the same workflow when you create a schedule in Revit so you can add or remove parameters, like the last picture.
Thanks!
publicpartialclassForm1:Form
{
List<string> l2;
string selectedItemText;
intSelectedIndex;
publicForm1()
{
InitializeComponent();
l2 =newList<string>();
l2.Add("1");
l2.Add("2");
l2.Add("3");
l2.Add("4");
l2.Add("5");
listBox1.DataSource= l2;
}
privatevoidForm1_Load(object sender,EventArgs e)
{
listBox1.Items.Clear();
foreach(object item inProperties.Settings.Default.listSave)
{
listBox1.Items.Add(item);
}
listBox2.Items.Clear();
foreach(object item inProperties.Settings.Default.listSave2)
{
listBox2.Items.Add(item);
}
}
privatevoid button1_Click(object sender,EventArgs e)
{
this.Close();
Properties.Settings.Default.listSave.Clear();
Properties.Settings.Default.listSave2.Clear();
foreach(object item in listBox1.Items)
{
Properties.Settings.Default.listSave.Add(item.ToString());
}
foreach(object item in listBox2.Items)
{
Properties.Settings.Default.listSave2.Add(item.ToString());
}
Properties.Settings.Default.Save();
}
privatevoid button2_Click_1(object sender,EventArgs e)
{
selectedItemText = listBox1.SelectedItem.ToString();
SelectedIndex= listBox1.SelectedIndex;
listBox2.Items.Add(selectedItemText);
if(l2 !=null)
{
l2.RemoveAt(SelectedIndex);
}
DataBindings();
}
privatevoidDataBindings()
{
listBox1.DataSource=null;
listBox1.DataSource= l2;
}
privatevoid button4_Click(object sender,EventArgs e)
{
selectedItemText = listBox2.SelectedItem.ToString();
SelectedIndex= listBox2.SelectedIndex;
l2.Add(selectedItemText);
listBox2.Items.RemoveAt(listBox2.Items.IndexOf(listBox2.SelectedItem));
DataBindings();
}
}
Solved! Go to Solution.