none
Column name not found RRS feed

  • Question

  • I want to format cell font color based on cell value in a RowAdded event.  I am adding values from an Sql Server, the column headers are the table columns names.

    int rowIndex = e.RowIndex;
    if(Convert.ToDateTime(DataGridView.Rows[rowIndex].Cells["ColumnName"].Value) < DateTime.Today)

    When I run the application I get

    System.ArgumentException: 'Column named ColumnName cannot be found.
    Parameter name: columnName'

    Any idea why its not recognizing the column name? 

    Wednesday, August 21, 2019 10:06 PM

Answers

All replies

  • Hi RichardDunneBSc,

    Welcome to the MSDN forum.

    According to your description, it seems that there is an error in your data source.So please follow these steps to have a try:

      1. please check the data source of the DataGridView to check if the wrong data source is  tied.

    Or the data source is null which there is an error in the query data source statement.

    >>You can perform breakpoint debugging on datagridview.datasource to view the problem.

      2. make sure the ColumName is the one of the actual field of your data source.It must be consistent with the fields in the data source.

    Any feedback will be expected.

    Best Regards,

    Perry



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com





    Thursday, August 22, 2019 3:12 AM
  • Its working now.  No idea what caused the exception or what fixed it.  Put it down to Gremlins.
    Friday, August 23, 2019 9:46 AM
  • Hi RichardDunneBSc,

    Thanks for your feedback.

    We are glad to hear that your issue solved. lf you have any other issue later, please feel free to let us know. We are willing to help you further.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, August 23, 2019 9:56 AM