The DataGrid gets datagridrow and DataGridColumn

Source: Internet
Author: User
Tags wpf datagrid

1 /* ----------------------------------------------------------2 file name: DataGridPlus.cs3 4 Qin Jianhui5 6 Msn:[email protected]7 qq:367488978 9 Blog:Http://blog.csdn.net/jhqinTen  One Development Environment: A Visual Studio V2010 - . NET Framework 4 Client profile -  the Version history: - V1.0 June 07, 2012 - WPF DataGrid Control extension Method -  + References: -     http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b7299e55-92e2-4a6b-8987-869fef8f22eb/ + ------------------------------------------------------------ */ A usingSystem.Windows.Controls; at usingSystem.Windows.Controls.Primitives; - usingSystem.Windows.Media; -  - namespaceSPLASH.WPF - { -      Public Static classDatagridplus in     { -         /// <summary> to         ///get the DataGrid control cell +         /// </summary> -         /// <param name= "DataGrid" >DataGrid Control</param> the         /// <param name= "RowIndex" >the line number where the cell is located</param> *         /// <param name= "ColumnIndex" >the column number where the cell is located</param> $         /// <returns>the specified cell</returns>Panax Notoginseng          Public StaticDataGridCell Getcell ( ThisDataGrid DataGrid,intRowIndex,intcolumnindex) -         { theDataGridRow Rowcontainer =Datagrid.getrow (rowIndex); +             if(Rowcontainer! =NULL) A             { theDatagridcellspresenter presenter = getvisualchild<datagridcellspresenter>(Rowcontainer); +DataGridCell cell =(DataGridCell) presenter. Itemcontainergenerator.containerfromindex (columnindex); -                 if(Cell = =NULL) $                 { $ Datagrid.scrollintoview (Rowcontainer, Datagrid.columns[columnindex]); -Cell =(DataGridCell) presenter. Itemcontainergenerator.containerfromindex (columnindex); -                 } the                 returncell; -             }Wuyi             return NULL; the         } -  Wu         /// <summary> -         ///get row of DataGrid About         /// </summary> $         /// <param name= "DataGrid" >DataGrid Control</param> -         /// <param name= "RowIndex" >DataGrid Row Number</param> -         /// <returns>the specified line number</returns> -          Public StaticDataGridRow GetRow ( ThisDataGrid DataGrid,intRowIndex) A         { +DataGridRow Rowcontainer =(DataGridRow) DataGrid.ItemContainerGenerator.ContainerFromIndex (rowIndex); the             if(Rowcontainer = =NULL) -             { $ datagrid.updatelayout (); the Datagrid.scrollintoview (Datagrid.items[rowindex]); theRowcontainer =(DataGridRow) DataGrid.ItemContainerGenerator.ContainerFromIndex (rowIndex); the             } the             returnRowcontainer; -         } in  the         /// <summary> the         ///gets a child visual of the first specified type in the parent visual object About         /// </summary> the         /// <typeparam name= "T" >visual Object Type</typeparam> the         /// <param name= "parent" >Parent Visual Object</param> the         /// <returns>the first child visual object of the specified type</returns> +          Public StaticT getvisualchild<t> (Visual parent)wheret:visual -         { theT Child =default(T);Bayi             intNumvisuals =Visualtreehelper.getchildrencount (parent); the              for(inti =0; i < numvisuals; i++) the             { -Visual v =(Visual) visualtreehelper.getchild (parent, i); -Child = V asT; the                 if(Child = =NULL) the                 { theChild = getvisualchild<t>(v); the                 } -                 if(Child! =NULL) the                 { the                      Break; the                 }94             } the             returnChild ; the         } the     }98}

The DataGrid gets datagridrow and DataGridColumn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.