1
Vote

Unable to cast object of type 'System.String' to type 'JDHSoftware.Krypton.Toolkit.KryptonOutlookGrid.CustomsColumns.TextAndImage'

description

I create a winform and a column with Header Order Status Name = CurrentOrderStatus, Column Type = KryptonDataGridViewTextAndImageColumn but when i run the application this give me exception ' Unable to cast object of type 'System.String' to type 'JDHSoftware.Krypton.Toolkit.KryptonOutlookGrid.CustomsColumns.TextAndImage' below is the code that i am using for bind the gridview
 foreach(DataRow _rowinDR in dt.Rows)
                   {
                      row = new OutlookGridRow();
 new TextAndImage(_rowinDR["CurrentOrderStatus"].ToString(),GetImageDescription(_rowinDR["CurrentOrderStatus"].ToString()))
                        });
                         l.Add(row);
                   }

                   datagridview.ResumeLayout();
                   datagridview.AssignRows(l);
                   datagridview.ForceRefreshGroupBox();
                   datagridview.Fill();  
}
The function that is used in your example i create same function
private Image GetImageDescription(string CurrentOrderStatus)
        {
            switch (CurrentOrderStatus)
            {
                case "In Transit":
                    return Properties.Resources.transit;
                case "Arrived":
                    return Properties.Resources.accepted;
                case "Dispatched":
                    return Properties.Resources.dispatched;
                case "Pickedup":
                    return Properties.Resources.pickedup;
                case "Dropped Off":
                    return Properties.Resources.droppedoff;
                default:
                    return null;
            }
        }
I have include the all the png file in resx file .Can you please tell me what i am doing wrong. i am creating demo in VS 2010 version 4.0 . Thanks for your help and comment

comments

Cocotteseb wrote May 6, 2014 at 6:18 PM

Hi,

Can you try this ?
 foreach(DataRow _rowinDR in dt.Rows)
                   {
                      row = new OutlookGridRow();
                      row.CreateCells(<youroutlookgrid>>, new Object[] { new TextAndImage(_rowinDR["CurrentOrderStatus"].Value ?? String.Empty,GetImageDescription(_rowinDR["CurrentOrderStatus"].Value ?? String.Empty)) });
                         l.Add(row);
                   }

                   datagridview.ResumeLayout();
                   datagridview.AssignRows(l);
                   datagridview.ForceRefreshGroupBox();
                   datagridview.Fill();  
}
You must use CreateCells function to create the cells for the row.
Does this helps ?