none
Read current cell value in Wpf datagrid

    Question

  • Hai 

         Purpose: To make custom column to enter only decimals (inlcuding period once).

         I use Code below to read current cell value from Datagrid in PreviewKeyDown.
    and I am getting the value also.The content received is like this
    "System.Windows.Controls.DataGridCell:" then cell text. But I want only the Content of cell.
    Please tell me how to get this and I want this in PreviewKeyDown event or OnPreviewTextInput.

    var cellInfo = Dgv.SelectedCells[0];
                var cellContent = GetDataGridCell(cellInfo);
                string xx = Convert.ToString(cellContent);
                MessageBox.Show(Convert.ToString(xx));
    
    
         public DataGridCell GetDataGridCell(DataGridCellInfo cellInfo)
            {
                var cellContent = cellInfo.Column.GetCellContent(cellInfo.Item);
                if (cellContent != null)
                    return (DataGridCell)cellContent.Parent;
                return null;
    
            }
    
         void OnPreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
             {
    
                e.Handled = new Regex("[^0-9.]").IsMatch(e.Text);
            }


    I want to check weather period exist more than once. Or is there any alternate.

    Thanks


    programmer

    Saturday, October 15, 2016 8:40 AM

Answers

All replies