Revit parameter form listbox to listbox

Revit parameter form listbox to listbox

vanlion
Advocate Advocate
1,750 Views
7 Replies
Message 1 of 8

Revit parameter form listbox to listbox

vanlion
Advocate
Advocate

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();
    }
}

 

9KXHz.png1.PNG

0 Likes
Accepted solutions (2)
1,751 Views
7 Replies
Replies (7)
Message 2 of 8

BenoitE&A
Collaborator
Collaborator
Accepted solution

Hey Vanlion,

I assume you know some stuff on windows and events in C#. If not, there are some good courses about that and that would be a start.

 

You change the content of list 1 and 2 only by clicking on the >> and << buttons. So all your code will be associated with these 2 buttons.

Button >> has the following in its Click event : 

 

List<string> listSelected = new List<string>();

foreach(string str in Lb_left.SelectedItems)

{

listSelected.Add(str);

}

foreach(string str in listSelected)

{

this.LB_left.Items.Remove(str);

this.LB_right.Items.Add(str);

}

 

You do the same with the other button << and you're done.

Hope it helps

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 3 of 8

vanlion
Advocate
Advocate
Accepted solution

Hi Benoit FAVRE,

 

Thanks for taking your time to help!

 

With the replacement of mine code part with yours and changing getting the listbox data from:

 

listbox1.DataSource = "Your list";

to:

foreach (object obj in colName)
{
       listBox1.Items.Add(obj);
}

it is working very nice and reminds the user settings 😄 so it also went wrong with the DataSource

see attached GIF for the result! (Revit fragment)

So thanks again!

 

Concept1.gif

 

 

0 Likes
Message 4 of 8

vanlion
Advocate
Advocate

Benoit FAVRE,

 

I have one question remaining about this topic. I can save the listbox 1 and 2 layout with the  "properties.settings.default" this is working well when you always have the same items in a list.

 

But i like to receive custom shared parameters in the list. That's not a problem but when you have a new project without these custom shared parameters. They still got visible in the list because of they are saved to the "properties.settings"

 

How is this part working with Revit, like when you make a new schedule and add or delete parameters to the schedule Revit reminds your choices. But in my case i use a datagridview with listboxes.

 

I tried to find solutions on the internet but couldn't find a good example.

 

Concept2.gif

0 Likes
Message 5 of 8

BenoitE&A
Collaborator
Collaborator

Hey Vanlion,

I can't understand neither your problem nor the question. Can you explain ?

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 6 of 8

vanlion
Advocate
Advocate

Hi,

 

Thanks for your quick response. The thing i'm looking for is as you can see in the GIF image below.

 

When you add a Sheetlist for exmple you can add the available fields to a second listbox. When you are finished and click on the edit fields tab you see the second listbox reminds the fields you have added. This is the part i can't get to work/ find how to do it.

 

Is this more clear for you what my question is?

 

Otherwise, let me know 🙂 

 

Concept2.gif

0 Likes
Message 7 of 8

BenoitE&A
Collaborator
Collaborator

Hey,

Not sure that I understand your question but I'll try.

You want the information modified by user (what he puts in second listBox) to "stay" between 2 uses of your algo.

This means that you have to save some informations on your memory.

You have multiple ways to do this, from creating a text file somewhere to using Jeremy's Schemas.

Then when your algo will be started again you have to initialize it with a part where you will load the informations of the past session.

Hope it helps

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Message 8 of 8

vanlion
Advocate
Advocate

Hi,

 

Thanks for helping me. I will try to make a text file that will store the user settings in the listboxes instead of using the 

"properties.settings.default…"

 

I was hoping that the SDK has a good simple example but couldn't find it. so I try it with a text file.

 

Thanks again

0 Likes