G
Gordon Padwick
I'm in the process of attempting to climb the steep WPF learning cliff
(using Visual Studio 2008) and have run into a problem with displaying a
count of the number of items in a WPF ListBox.
My application displays data from an Access database in a ListBox within a
Grid. In markup, the ListBox defiinition contains:
Name = "familyList"
ItemsSource = "{Binding Path = familyData}"
ItemTemplate = "{StaticResource = FamilyTemplate}"
The Window element contains:
Loaded = "GetData"
Code behind contains the GetData method that consists of the usual C#
statements to connect to the database table and ends with the statements
myDataSet = new DataSet();
myAdapter.Fill(myDataSet, "familyData");
numFamily.Text = familyList.Items.Count.ToString();
numFamily is the name of a TextBox.
The application builds okay and runs okay as far as displaying database
items in the ListBox. However, the TextBox always display 0 (zero) despite
many items being listed.
The problem seems to be that the Count statement is executed before the
ListBox is filled, even though that satement occurs after the Fill statement
in the GetData method.
So, my question is: How can I get a count of the number of items in the
ListBox and display that number in a TextBox under the ListBox? I hope I've
provided enough information to enable someone to answer this question.
Thanks for any help offered.
Gordon Padwick
(using Visual Studio 2008) and have run into a problem with displaying a
count of the number of items in a WPF ListBox.
My application displays data from an Access database in a ListBox within a
Grid. In markup, the ListBox defiinition contains:
Name = "familyList"
ItemsSource = "{Binding Path = familyData}"
ItemTemplate = "{StaticResource = FamilyTemplate}"
The Window element contains:
Loaded = "GetData"
Code behind contains the GetData method that consists of the usual C#
statements to connect to the database table and ends with the statements
myDataSet = new DataSet();
myAdapter.Fill(myDataSet, "familyData");
numFamily.Text = familyList.Items.Count.ToString();
numFamily is the name of a TextBox.
The application builds okay and runs okay as far as displaying database
items in the ListBox. However, the TextBox always display 0 (zero) despite
many items being listed.
The problem seems to be that the Count statement is executed before the
ListBox is filled, even though that satement occurs after the Fill statement
in the GetData method.
So, my question is: How can I get a count of the number of items in the
ListBox and display that number in a TextBox under the ListBox? I hope I've
provided enough information to enable someone to answer this question.
Thanks for any help offered.
Gordon Padwick