读书人

datagrid 怎么获取列数据

发布时间: 2012-09-11 10:49:03 作者: rapoo

datagrid 如何获取列数据
急急急!!


string sLon;
sLon = dataGrid2.Columns[4].ToString();


获取不到列的数据???

[解决办法]
没有直接的API获取Column数据,可以通过以下代码:

C# code
private void FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)    {        DataGrid dataGrid = sender as DataGrid;        int selectedIndex = dataGrid.SelectedIndex;        if (selectedIndex > -1)        {            FindResult findResult = (FindResult)FindDetailsDataGrid.SelectedItem;            DataGridColumn column = dataGrid.Columns[0];            FrameworkElement fe = column.GetCellContent(dataGrid.SelectedItem);            FrameworkElement result = GetParent(fe, typeof(DataGridCell));            if (result != null)            {                DataGridCell cell = (DataGridCell)result;                             cell.Foreground = new SolidColorBrush(Colors.Blue);                      TextBlock block = fe as TextBlock;                if (block != null)                {                    string cellText = block.Text;                    MessageBox.Show(cellText);                }            }        }    } 

读书人网 >CAD教程

热点推荐