How to access cells of WPF Toolkit DataGrid?

Apr 14, 2010 at 10:15 PM
Edited Apr 14, 2010 at 10:17 PM

Hi! I'm trying to retrieve and modify the value of a cell in a WPF Toolkit datagrid but I can't figure out how I can do it. My test application contains only a datagrid which displays an IEnumerable<string>.

 

        <Toolkit:DataGrid ItemsSource="{Binding Numbers}" AutoGenerateColumns="False">
            <Toolkit:DataGrid.Columns>
                <Toolkit:DataGridTextColumn Header="Number" IsReadOnly="True" Binding="{Binding}" />
            </Toolkit:DataGrid.Columns>
        </Toolkit:DataGrid>

In my test, I get the data grid by window.Get<ListView>(). I can also access the header and its columns and I also see that the data grid has some rows, but I cannot access the cells collection because it is always empty. Am I doing something wrong? Here is my test fixture:

    [TestFixture]
    public class When_adding_numbers
    {
        private Application _application;
        private Window _window;

        [SetUp]
        public void BeforeEveryTest()
        {
            _application = Application.Launch(typeof (Shell).Assembly.GetName().Name + ".exe");
            _window = _application.GetWindows().Single();

            _window.Get<TextBox>("MinTextBox").Enter("10");
            _window.Get<TextBox>("MaxTextBox").Enter("100");
            _window.Get<Button>("AddButton").Click();
            _window.Get<Button>("AddButton").Click();
        }

        [Test]
        public void Should_add_number_to_list_box()
        {
            var listView = _window.Get<ListView>();
            System.Diagnostics.Debug.WriteLine("cell count: " + listView.Rows[0].Cells.Count);
            Assert.That(Convert.ToInt32(listView.Rows[0].Cells[0].Text), Is.GreaterThanOrEqualTo(10).And.LessThan(100));
        }

        [TearDown]
        public void AfterEveryTest()
        {
            _application.Kill();
        }
    }

 

 Best Regards, Oliver Hanappi

Apr 15, 2010 at 10:50 AM

Hi

 

have a look here: WPF DataGrid

 

may that will help you

 

Throndorin