2

I have a List of string and I need display the values of this list in a DataGrid. I have this:

public void DisplaySetInformation2(List<string> setList)
{
    for (int i = 0; i < setList.Count; i++)
    {
        _dataGridSection.ItemsSource = setList[i].ToString();
    }
}

but it does not work.

What can I do?

1
  • You should have tagged it under Silverlight. Commented May 24, 2011 at 18:11

3 Answers 3

2

You will have to do something like this..

create a class which will contain string

 public class StringValue
        {
            public StringValue(string value)
                {
                stringValue = value;
                }

             public string stringValue {get; set;}
        }

create a List<StringValue> stringValues = new List<StringValue>(){new StringValue("Hello"), new StringValue("World")};

then dataGrid.ItemsSource = stringValues;

Sign up to request clarification or add additional context in comments.

Comments

0

You don't need to add every item. Just set the list as datasource.

_dataGridSection.ItemsSource = setList;

1 Comment

Are you sure this will work? this will only display string length in datagrid column.
0

You may want to try a DataGridView instead. That will probably be easier to work with.

Comments

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.