Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Casting error question

Casting error question

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kanchoette
    wrote on last edited by
    #1

    I am using: foreach (DebtorDataSet.PaymentArrangementsRow row in debtorDataSet.PaymentArrangements.Rows) { if (row.PaymentArrangementID != -1 && row.PaymentTypeID == Convert.ToInt32(paymentCategoryComboBox.SelectedItem) && row.ArrangementComplete == false) { row.ArrangementComplete = true; row.ArrangementDate = DateTime.Today; } } but this is giving me the error: 'Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'' I am not sure how to correct this. Any help would be much appreciated please.

    C 1 Reply Last reply
    0
    • K kanchoette

      I am using: foreach (DebtorDataSet.PaymentArrangementsRow row in debtorDataSet.PaymentArrangements.Rows) { if (row.PaymentArrangementID != -1 && row.PaymentTypeID == Convert.ToInt32(paymentCategoryComboBox.SelectedItem) && row.ArrangementComplete == false) { row.ArrangementComplete = true; row.ArrangementDate = DateTime.Today; } } but this is giving me the error: 'Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'' I am not sure how to correct this. Any help would be much appreciated please.

      C Offline
      C Offline
      Covean
      wrote on last edited by
      #2

      I'm not really sure about it, but because there is only one line where you convert something I would replace

      Convert.ToInt32(paymentCategoryComboBox.SelectedItem)

      with

      Convert.ToInt32(paymentCategoryComboBox.SelectedItem.ToString())

      But in general SelectedItem is not from the type 'System.Data.DataRowView' so I'm a little bit confused with it. But maybe that helps.

      Greetings Covean

      K 1 Reply Last reply
      0
      • C Covean

        I'm not really sure about it, but because there is only one line where you convert something I would replace

        Convert.ToInt32(paymentCategoryComboBox.SelectedItem)

        with

        Convert.ToInt32(paymentCategoryComboBox.SelectedItem.ToString())

        But in general SelectedItem is not from the type 'System.Data.DataRowView' so I'm a little bit confused with it. But maybe that helps.

        Greetings Covean

        K Offline
        K Offline
        kanchoette
        wrote on last edited by
        #3

        Many thanks for your reply. Sill me realised that I needed SelectedValue instead of selectedItem to do the job. The perils of late night coding .......

        C P 2 Replies Last reply
        0
        • K kanchoette

          Many thanks for your reply. Sill me realised that I needed SelectedValue instead of selectedItem to do the job. The perils of late night coding .......

          C Offline
          C Offline
          Covean
          wrote on last edited by
          #4

          Hehe. On the other hand its sometimes very funny to look over code you wrote in a stressful time. Sometime its a bloomer just for the Coding Horrors section. :laugh:

          Greetings Covean

          1 Reply Last reply
          0
          • K kanchoette

            Many thanks for your reply. Sill me realised that I needed SelectedValue instead of selectedItem to do the job. The perils of late night coding .......

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            What type is the SelectedValue? If it's an int, why convert an int to an int? Just cast it. If not, then you can probably cast it anyway. I find the Convert class to be nearly entirely useless; try not to use it.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups