简体   繁体   中英

ItemContainerGenerator.Items in .NET 4.0

I started a project using .NET 4.5, now I have to switch to .NET 4.0. Everything works fine, except the "Items"-Property of ItemContainerGenerator is missing. I use it to find the row of a DataGrid that starts with the letter of a typed key. The Code is:

     ReadOnlyCollection<object> rows = datagrid.ItemContainerGenerator.Items;
     datagrid.ScrollIntoView(rows[rows.Count - 1]);
     foreach (DataRowView row in rows)
     {
          string name = row.Row.ItemArray[0].ToString();
          if (name.StartsWith(keyChar + "", StringComparison.OrdinalIgnoreCase))
          {
               datagrid.ScrollIntoView(row);
               datagrid.UpdateLayout();
               return;
          }
     }

Note: When debugging, the "Items"-Property is present and filled.

Do you know a way to access the "Items"-Property or a workaround to get the same function without using the "Items"-Property? Any suggestions will be welcomed.

The ItemContainerGenerator.Items seems to be present in .NET 4.0: https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid_properties(v=vs.100).aspx

.NET Framework 4 Other Versions

...

ItemContainerGenerator Gets the ItemContainerGenerator that is associated with the control. (Inherited from ItemsControl.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM