1

I'm relatively new to .NET GUI programming using WinForms (the project I'm working on is targetting .NET 2.0 for deployment reasons), and I'm trying to bind a ListBox in a Form to a string[] property that is defined in the form:

namespace AVPriorityUI
{
    public partial class AVPriorityUI : Form
    {
        public AVPriorityUI()
        {
            InitializeComponent();
        }

        public string[] ProcessNames
        {
            get { ... }
            set { ... }
        }
    }
}

No matter what I do, I can't get Visual Studio 2008 to offer up the ProcessNames property as a valid source to bind to. What do I need to do differently to make this work?

[EDIT] I've been trying to use the GUI to establish the binding.

3 Answers 3

1

You should be able to set the list box's DataSource to the ProcessNames property in the code itself. If you are trying to use the UI to set the DataSources/Bindings that may be the culprit.

ie:

mylistBox.DataSource = this.ProcessNames;
Sign up to request clarification or add additional context in comments.

1 Comment

That was it... I've never seen a UI that works for the complex case but fails utterly at the trivial... :(
0

http://msdn.microsoft.com/en-us/library/aa288424(VS.71).aspx

listbox.Items.AddRange(this.ProcessNames);

1 Comment

scratch my solution... old c# syntax.... no longer valid in 2.0 and higher it seems....
0

this works for me in a simple test just now:

string[] alist = { "a", "b", "c", "d", "e", "f", "g", "h" };
listBox1.DataSource = alist;

1 Comment

How do you make this work if alist is a globally scoped variable and you add more elements after databinding?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.