locked
How to get the row count of a grid component? RRS feed

  • Question

  • Hi,
    I am new to wpf.
    I need to know number of rows that are present in a grid from the code programmatically.

    I observed that grid.children.count

    will it give number of rows or not?

    Any help is much more appreciated.
    Wednesday, November 25, 2009 2:52 PM

Answers

  • If you are talking about Grid Layout then it would be

    int gridRow =  grid.RowDefinitions.Count; 
    If you are talking about DataGrid introduced in WPF 4 (.Net 4.0 Beta 2) then it would be

    int dataGridRow = datagrid.Items.Count;
    Here gridRow and dataGrid row are the name of the variables Grid and DataGrid respectively.

    Zeeshan Amjad
    http://zamjad.wordpress.com/

    Wednesday, November 25, 2009 4:19 PM

All replies

  • Hi Vema,

    what kind of "grid" are you talking about? If you're refering to the DataGrid (found in the WPF-toolkit) or i.e. a ListView, you can obtain the count of "rows" via ControlName.Items.Count (provided you have actually named the control).
    Cheers,
    Olaf
    Wednesday, November 25, 2009 4:05 PM
  • If you are talking about Grid Layout then it would be

    int gridRow =  grid.RowDefinitions.Count; 
    If you are talking about DataGrid introduced in WPF 4 (.Net 4.0 Beta 2) then it would be

    int dataGridRow = datagrid.Items.Count;
    Here gridRow and dataGrid row are the name of the variables Grid and DataGrid respectively.

    Zeeshan Amjad
    http://zamjad.wordpress.com/

    Wednesday, November 25, 2009 4:19 PM