1

I feel like there's something about grids that I'm missing, but I can't find it through Googling around.

For example, I want to be able to declare ten rows with ten columns, populate them with data, and then later realize that I don't need row 3, and be able to quickly reformat it. I'm not speaking of doing this programmatic, but while redesigning the project. One way that this could be handled in theory would be HTML's manner of deleting a set of <tr></tr>s. This would be limited to rows, obviously. Another way might be the ability to give each column a name, such as "CityColumn," "StateColumn" (or named whatever else depending on the use of Grid), and then simply deleting the column's definition and all elements declared to exist in the column.

As is, if you delete any given row or column, you must go to each and every element that appears in a later row or column and change the row or column's number. It seems like there should be a better way to use XAML's grid that I'm not making use of.

While I lack a clear question that I can define, it can be said that I'm looking for best practices and/or any tips and tricks to make Grid easy to modify it and its contents and, in general, provide upkeep for.

Either explanations or links to learning resources about XAML's Grid would be welcome.

Canin
  • 129
  • 1
  • 10
  • You could extend it via attached properties, but what you ask for isn't built in. – Louis Kottmann Jul 25 '12 at 18:37
  • Use the [`Grid`](http://msdn.microsoft.com/en-us/library/system.windows.controls.grid) for laying out _controls_ in your application. You're trying to layout _data_. Sounds to me like you should be using a [`ListView`](http://msdn.microsoft.com/en-us/library/system.windows.controls.listview) control with a [`GridView`](http://msdn.microsoft.com/en-us/library/system.windows.controls.gridview.aspx) view. – Jeff Mercado Jul 25 '12 at 18:40
  • Actually technically my team _is_ layout controls for a window and custom dialog boxes. I suppose my example in my question isn't the best. I can edit the question's example if it'd rephrase it for clarity's sake. – Canin Jul 25 '12 at 18:43
  • I'd ask programming to write an add-in script. – Lee Louviere Jul 25 '12 at 21:07

1 Answers1

2

I would recommend what Jeff Mercado said: ListView with GridView as its View. The columns of that view can have headers, and if you remove an item the respective row is gone.

Also you can optimize the Grid maintainability, if you intend to stick with that, by using named references rather than indices, so if you remove one row that becomes much easier.

Community
  • 1
  • 1
H.B.
  • 166,899
  • 29
  • 327
  • 400