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. problem with propertygrid

problem with propertygrid

Scheduled Pinned Locked Moved C#
helptutorialquestion
2 Posts 2 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.
  • D Offline
    D Offline
    Deglimmer
    wrote on last edited by
    #1

    Hi, im using propertygrid and trying to show boolean property with other string values than true/false, i made boolenconverter for this, it works fine when i use combobox to change value, but i get inner propertygrid error when i doubleclick to change value in propertygrid: Invalid property value! Details: Cannot widen from target type to primitive type. public class BaseProps{ private bool test; [TypeConverter(typeof(BoolNameConverter2))] public bool Value { get {return test;} set {test = value;} } } public class BoolNameConverter2 : StringConverter { private const string m_trueDisplayName = "on"; private const string m_falseDisplayName = "off"; public override bool CanConvertTo(ITypeDescriptorContext context, System.Type destinationType) { if (destinationType == typeof(bool)) return true; return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { if (value is bool && destinationType == typeof(System.String)) { return (bool)value ? m_trueDisplayName : m_falseDisplayName; } return base.ConvertTo(context, culture, value, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType) { if (sourceType == typeof(string)) return true; return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { return (string)value == m_trueDisplayName ? true : false; } return base.ConvertFrom(context, culture, value); } public override bool GetStandardValuesSupported( ITypeDescriptorContext context) { return true; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { return new StandardValuesCollection (new string[]{m_trueDisplayName, m_falseDisplayName}); } public override bool GetStandardValuesExclusive( ITypeDescriptorContext context) { return true; } } What could be the problem? Has anybody had similar problem and has solution? How to fix it? Thanks Deglimmer

    V 1 Reply Last reply
    0
    • D Deglimmer

      Hi, im using propertygrid and trying to show boolean property with other string values than true/false, i made boolenconverter for this, it works fine when i use combobox to change value, but i get inner propertygrid error when i doubleclick to change value in propertygrid: Invalid property value! Details: Cannot widen from target type to primitive type. public class BaseProps{ private bool test; [TypeConverter(typeof(BoolNameConverter2))] public bool Value { get {return test;} set {test = value;} } } public class BoolNameConverter2 : StringConverter { private const string m_trueDisplayName = "on"; private const string m_falseDisplayName = "off"; public override bool CanConvertTo(ITypeDescriptorContext context, System.Type destinationType) { if (destinationType == typeof(bool)) return true; return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { if (value is bool && destinationType == typeof(System.String)) { return (bool)value ? m_trueDisplayName : m_falseDisplayName; } return base.ConvertTo(context, culture, value, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType) { if (sourceType == typeof(string)) return true; return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { return (string)value == m_trueDisplayName ? true : false; } return base.ConvertFrom(context, culture, value); } public override bool GetStandardValuesSupported( ITypeDescriptorContext context) { return true; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { return new StandardValuesCollection (new string[]{m_trueDisplayName, m_falseDisplayName}); } public override bool GetStandardValuesExclusive( ITypeDescriptorContext context) { return true; } } What could be the problem? Has anybody had similar problem and has solution? How to fix it? Thanks Deglimmer

      V Offline
      V Offline
      visualhint
      wrote on last edited by
      #2

      Hi, Your converter should derive from BooleanConverter. Just override the ConvertTo and ConvertFrom methods to change the display strings. Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker

      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