//--需要遍历的列
var cols = dataGrid1.Columns[2];

foreach (var item in dataGrid1.ItemsSource)
{
  //--数据源的实体对象
                B_ExContents contets = item as B_ExContents;
              
                //--对象所在的单元格
                var cells = cols.GetCellContent(item);
                if (cells != null)
                {
             //--单元格所包含的元素
                    TextBox txt = cells as TextBox;
                   
                }
}

2.遍历ListBox的方法
  //--开始遍历
    foreach (var item in listUsers.Items)
                    {
                        //item 是数据源中的一个实体对象
                        ListBoxItem obj = listUsers.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
                        if (obj != null)
                        {
                            obj.Background = new SolidColorBrush(Colors.Green);
                        }
                    }

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xinfu032/archive/2010/10/25/5964242.aspx

相关文章:

  • 2021-06-24
  • 2022-01-02
  • 2021-09-07
  • 2021-11-14
  • 2021-07-29
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2022-12-23
  • 2021-06-09
  • 2022-02-02
  • 2021-12-08
  • 2022-01-24
  • 2021-05-22
相关资源
相似解决方案