DataGrid.Current is Always Invalid

RogerSchlueter-7899 1,801 Reputation points
2026-12-03T16:58:22.43+00:00

I have written a small VB app that Illustrates the issue; I've uploaded the essential files; it should be obvious how to extract the individual files from that concatenation and rebuild the app.

The application just creates a DataGrid then populates it with a single row DataTable. As shown by clicking the button, no matter how one clicks in the DataGrid, CurrentCell.IsValid is ALWAYS False. How can this be fixed?

Developer technologies | VB

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 85,506 Reputation points
    2026-12-03T21:09:23.9533333+00:00

    if you are using window forms, then you should be using DataGridView, if WPF then DataGrid. In neither is cell.IsValid supported. vb6 is no longer supported.

    Was this answer helpful?

    1 person found this answer helpful.

  2. Brian Pham (WICLOUD CORPORATION) 1,595 Reputation points Microsoft External Staff Moderator
    2026-12-04T03:00:30.1233333+00:00

    Hi @RogerSchlueter-7899 ,

    Thank you for the clarification.

    You're correct that DataGridCellInfo.IsValid is a supported property in WPF. As documented in Microsoft Learn, the DataGrid.CurrentCell property returns a DataGridCellInfo structure, which provides the IsValid property.

    According to the documentation, IsValid returns False when either of the following conditions is met:

    • The Item property is DependencyProperty.UnsetValue.
    • The Column property is Nothing (null in C#).

    Since you've mentioned that CurrentCell.IsValid consistently returns False even after clicking different cells, it would be helpful to determine which of these conditions is occurring.

    Could you please check the values of DataGrid.CurrentCell.Item and DataGrid.CurrentCell.Column after clicking a cell?

    You can use the following VB.NET code to inspect the current cell information:

    Dim cellInfo = MyDataGrid.CurrentCell
    
    Debug.WriteLine(
        $"CurrentCell.IsValid: {cellInfo.IsValid}"
    )
    
    Debug.WriteLine(
        $"Item is UnsetValue: {Object.ReferenceEquals(cellInfo.Item, DependencyProperty.UnsetValue)}"
    )
    
    Debug.WriteLine(
        $"Column is Nothing: {cellInfo.Column Is Nothing}"
    )
    
    

    Please replace MyDataGrid with the name of your DataGrid control. This check would help determine whether the current cell is considered invalid because its item or column information is missing. However, it would not necessarily establish why that information is not being updated when a cell is clicked.

    Additionally, could you please confirm which .NET Framework or .NET version your WPF application is targeting (for example, .NET Framework 4.8 or .NET 10)?

    I appreciate the time you've taken to prepare and share a sample application. The results of these checks, along with the target framework version, would help narrow down the behavior you're experiencing.

    If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation.

    Thank you.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.