0

I am a programmer for winforms and asp.net. A new-comer to WPF application development.

I wish to thank in advance for any help rendered to my query,

I am working on a application for Banking. My job profile is to develop reusable usercontrols for the application.

An example would be to make a Simple numeric input box which has Max and Min number properties. So the control pops an error if the number entered is not within a range. (ofcourse there is much more to this control :-)

On similar lines. I have to develop a listview user control with Two properties.

1) A comma separated values of column headers
2) A comma separated values of data to add

My colleague, now places this usercontrol on window (as known in WPF). and passes the above parameters to the listview control.

My coding ensures that the columns are placed and data is added. In winforms this is a simple process. In WPF i was able to achieve it for known columns by defining beforehand in observablecollection or otherwise using

SamplelistView.Items.Add(new { FirstName = "test1", LastName = "ABX", EmployeeNumber = "AAA111"});

However in the above mentioned command, Firstname,Lastname are previously known columns.

Is there any command like,adding data as a array or adding data directly to columns without binding to a collection. OR is there a way to add columns to observablecollections at runtime.

Pls. excuse my limited exposure on nomenclature and otherwise.

arvind
  • 1,385
  • 1
  • 13
  • 21

1 Answers1

0

My approach to this problem would be:

  1. Create a UserControl that hosts a DataGrid
  2. Add a ColumnNames dependency property to the UserControl. In the PropertyChanged event handler, parse the CSV and update the DataGrid.Column accordingly.
  3. Add a Data dependency property to the UserControl - and when this changes, parse the CSV and add the data to the DataGrid.

See this question for a few pointers:

programmatically add column & rows to WPF Datagrid

By the way, a CSV of column names is a horrible interface! Why not expose a List<string>, then add a TypeConverter so that you can use a CSV string in XAML?

Community
  • 1
  • 1
ColinE
  • 68,894
  • 15
  • 164
  • 232
  • Thank you, I will pass on your suggestion. I have looked into the above mentioned link. The topic on how to add columns in runtime for the placed grid is now solved. But however i am still searching on how to add the correspoding data into the grid. – arvind Jun 09 '11 at 09:12