Imagine you want to enumerate (enlist) all rows (DataGridRow) of Silverlight Grid (DataGrid). By design this is not very simple tasks. For example, you want to do something like this: foreach (DataGridRow rowItem in grid.Rows) { . . . } Th
Imagine you want to enumerate (enlist) all rows (DataGridRow) of Silverlight Grid (DataGrid). By design this is not very simple tasks.
For example, you want to do something like this:
foreach (DataGridRow rowItem in grid.Rows)
{
. . .
}
This very important and very frequent requirement is just an issue. You will notice that this is almost impossible and will start to research in internet. Good luck. So, I decided to post the code of extension class which makes this possible:
{
. . .
}
Here is the whole code:
///
/// Extends the DataGrid.
///
public static class DataGridExtensions
{
///
/// Gets the list of DataGridRow objects.
///
/// The grid wirhrows.
///
public static ICollection
{
List
foreach (var rowItem in grid.ItemsSource)
{
// Ensures that all rows are loaded.
grid.ScrollIntoView(rowItem, grid.Columns.Last());
// Get the content of the cell.
FrameworkElement el = grid.Columns.Last().GetCellContent(rowItem);
// Retrieve the row which is parent of given element.
DataGridRow row = DataGridRow.GetRowContainingElement(el.Parent as FrameworkElement);
// Sometimes some rows for some reason can be null.
if (row != null)
rows.Add(row);
}
return rows;
}
}
The code above shows theoretically the idea of accessing of rows. Unfortunately this will work only if the whole grid result can be placed at the current view. While calling of ScrollIntoView() grid will reuse instances of created cells and rows and replace
with new bounded data over and over again. The result of so called row virtualization will be replacing of rows in the list.
To workaround this, I implemented the right extension method
public static IEnumerator
{
return new GridRowEnumerator(grid);
}
And here is the implementation of enumerator:
public class GridRowEnumerator : IEnumerator
{
private DataGrid m_Grid;
private IEnumerator m_Enumerator;
public GridRowEnumerator(DataGrid grid)
{
m_Grid = grid;
m_Enumerator = m_Grid.ItemsSource.GetEnumerator();
}
#region IEnumerator
public DataGridRow Current
{
get
{
var rowItem = m_Enumerator.Current;
// Ensures that all rows are loaded.
m_Grid.ScrollIntoView(rowItem, m_Grid.Columns.Last());
// Get the content of the cell.
FrameworkElement el = m_Grid.Columns.Last().GetCellContent(rowItem);
// Retrieve the row which is parent of given element.
//DataGridRow row = DataGridRow.GetRowContainingElement(el);
DataGridRow row = DataGridRow.GetRowContainingElement(el.Parent as FrameworkElement);
return row;
}
}
#endregion
#region IDisposable Members
public void Dispose()
{
}
#endregion
#region IEnumerator Members
object IEnumerator.Current
{
get
{
return this.Current;
}
}
public bool MoveNext()
{
return m_Enumerator.MoveNext();
}
public void Reset()
{
m_Enumerator.Reset();
}
#endregion
}
…
This line I put here to measure how some interesting words can dramatically increase landing frequency of boring technical posts.
Bayern Inter Football Soccer champions league
Please forgive me for this :)
Posted May 02 2010, 12:30 AM by Damir Dobric
Filed under: Silverlight

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.