This is a migrated thread and some comments may be shown as answers.

Auto suggestion box in Grid

7 Answers 135 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Kaven
Top achievements
Rank 1
Kaven asked on 25 Oct 2012, 03:55 PM
Hello,

We currently have a field of our class that is the list of possible Texture that we can assign to a Sprite. It is a collection received by our Converter
class TextureConverter : ResourceConverter
    {
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            Type[] tType = new Type[] { typeof(Texture), typeof(TextureAtlas) };
            string[] tResource = ProjectManager.Singleton.CurrentProject.GetResourceNameListForType(tType, false);
            return new StandardValuesCollection(tResource);
        }
    }
And our class member goes like this:
[Category("Settings Sprite")]
        [DisplayName("Texture")]
        [Description("Current Texture")]
        [TypeConverter(typeof(TextureConverter))]
        public virtual string Texture
        {
            get
            {
                return mTextureCBValues;
            }
            set
            {
                if (mTextureCBValues != value)
                {
                    if (value == "")
                    {
                        ResetTexture();
                    }
                    else
                    {
                        Item tTex = ProjectManager.Singleton.CurrentProject.GetResourceByName(value, true, Name);
                        if (tTex is Texture)
                        {
                            mTextureCBValues = value;
                            SetTexture(tTex as Texture);
                        }
                        else if (tTex is TextureAtlas)
                        {
                            mTextureCBValues = value;
                            SetTextureAtlas(tTex as TextureAtlas);
                        }
                        else
                        {
                            SetStatus(Item.StatusState.ERROR, "Texture " + value + " is not found or invalid");
                            ResetTexture();
                        }
                    }
 
                    Refresh();
                    NotifyPropertyChanged();
                }
            }
        }

How is it possible to make that field so we can "search" (auto-suggestion) for the texture name we want?

Kaven

7 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 29 Oct 2012, 03:03 PM
Hello Kaven,

Thank you for writing.

RadPropertyGrid supports custom type converters and takes into account the standard values collection. To get this feature working you have to also override the GetStandardValuesSupported method, which is used to determine whether there are standard values or not. After you override it you will see that the property will be edited using a drop down editor which contains the standard values. You can enable the user to type in the drop down by subscribing to the EditorInitialized event and adding the following code to the event handler:
private void radPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
{
  if (e.Item.Name == "Texture")
  {
    PropertyGridDropDownListEditor editor = e.Editor as PropertyGridDropDownListEditor;
    BaseDropDownListEditorElement element = editor.EditorElement as BaseDropDownListEditorElement;
 
    element.DropDownStyle = RadDropDownStyle.DropDown;
    element.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  }  
}

I hope this will be useful. Should you have further questions, I would be glad to help.
 
Greetings,
Ivan Petrov
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Kaven
Top achievements
Rank 1
answered on 29 Oct 2012, 08:10 PM
Thanks!

Is there a way to let it suggest us the words that contains what we are typing and not only the one that begin with? Must we always change the DataSource each time a letter is typed?

On an other note, when we switched from PropertyGrid to RadPropertyGrid, we lost the Grouping and even if I set the EnableGrouping and/or EnableCustomGrouping to true.

Our class member are set up like this
[Category("Settings Sprite")]
[DisplayName("Texture")]
[Description("Current Texture")]
[TypeConverter(typeof(TextureConverter))]

Kaven
0
Ivan Petrov
Telerik team
answered on 01 Nov 2012, 01:16 PM
Hi Kaven,

Thank you for writing back.

You can get this functionality by altering a bit the example from my previous post. Here is the new code:
private void radPropertyGrid1_EditorInitialized(object sender, Telerik.WinControls.UI.PropertyGridItemEditorInitializedEventArgs e)
{
  if (e.Item.Name == "Texture")
  {
    PropertyGridDropDownListEditor editor = e.Editor as PropertyGridDropDownListEditor;
    BaseDropDownListEditorElement element = editor.EditorElement as BaseDropDownListEditorElement;
 
    element.DropDownStyle = RadDropDownStyle.DropDown;
    element.AutoCompleteMode = AutoCompleteMode.Suggest;
    element.AutoCompleteSuggest.SuggestMode = SuggestMode.Contains;
  
}
On the grouping functionality, the properties you have set control whether grouping and custom grouping are allowed as an operation. These properties do not perform an actual grouping. To change the grouping you can use the PropertySort property. It allows you to sort and/or group properties.

I hope this will help. 
 
Greetings,
Ivan Petrov
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Kaven
Top achievements
Rank 1
answered on 01 Nov 2012, 02:01 PM
Thanks for your reply.

I played a lot with PropertySort as it seemed the obvious thing but the only thing it does right now is that every property are seperated instead of actually being grouped. When the PropertySort is AlphabeticalCategorized,it looks like the image I attached when my code is this
[Category("Settings Font Creation")]
[DisplayName("Italic")]
[Description("Italic")]
public bool Italic
{
    get
    {
        return mItalic;
    }
    set
    {
        if (mItalic != value)
        {
            mItalic = value;
            Generate();
            UpdateFontChanges();
            NotifyPropertyChanged();
        }
    }
}
 
[Category("Settings Font Creation")]
[DisplayName("Font Name")]
[Description("Font Name")]
[ReadOnly(true)]
public String FontName
{
    get
    {
        return mFontName;
    }
    set
    {
        if (mFontName != value)
        {
            mFontName = value;
            Generate();
            UpdateFontChanges();
            NotifyPropertyChanged();
        }
    }
}
 
[Category("Settings Font Creation")]
[DisplayName("Font Outline")]
[Description("Font Outline")]
public byte Outline
{
    get
    {
        return mOutline;
    }
    set
    {
        if (mOutline != value)
        {
            mOutline = value;
            if (Generate() < 0)
            {
                // An Error occured
                MessageBox.Show("Bad value, No font generated!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            UpdateFontChanges();
            NotifyPropertyChanged();
        }
    }
}
 
[Category("Settings Font Creation")]
[DisplayName("Border Width")]
[Description("Border Width")]
public byte BorderWidth
{
    get
    {
        return mBorderWidth;
    }
    set
    {
        if (mBorderWidth != value)
        {
            mBorderWidth = value;
            Generate();
            UpdateFontChanges();
            NotifyPropertyChanged();
        }
    }
}
 
[Category("Settings Font Creation")]
[DisplayName("Exported Char")]
[Description("Exported Char")]
public String ExportChar
{
    get
    {
        return mExportChar;
    }
    set
    {
        if (mExportChar != value)
        {
            mExportChar = value;
            Generate();
            UpdateFontChanges();
            NotifyPropertyChanged();
        }
    }
}
 
[Category("Settings Font Creation")]
[DisplayName("Font Color")]
[Description("Font Color")]
public Color FontColor
{
    get
    {
        return mFontColor;
    }
    set
    {
        if (mFontColor != value)
        {
            mFontColor = value;
            UpdateFontChanges();
            NotifyPropertyChanged();
        }
    }
}
 
[Category("Settings Font Creation")]
[DisplayName("Optimized Texture Size")]
[Description("Optimized Texture Size")]
public Size FontTextureSize
{
    get
    {
        return new Size(mTextureWidth, mTextureHeight);
    }
}
 
[Browsable(false)]
public bool IsOptimizeMode
{
    get
    {
        return mIsOptimizeMode;
    }
    set
    {
        mIsOptimizeMode = value;
    }
}

I'm wondering why this use to work perfectly with the PropertyGrid.

Kaven
0
Kaven
Top achievements
Rank 1
answered on 01 Nov 2012, 02:53 PM
Ok. I got it working. Seems like we just need EnableGrouping enabled and not EnableCustomGrouping. I guess I turned them both on during my tests.

Thanks for your help. It is much appreciated.
0
ishara
Top achievements
Rank 1
answered on 16 Nov 2012, 07:50 AM
HI,

is there any way that i can use Autocomplete with PropertyGridTextBoxEditor ?

Thanks ,
Ishara
0
Ivan Petrov
Telerik team
answered on 20 Nov 2012, 05:13 PM
Hello Ishara,

Your question was already answered in the other thread you have opened. Please see our answer there for more information.

We would like to kindly ask you to use just one support channel to contact us. Posting the same question more than once slows down our response time because we will need to review and address two or more threads instead of one. Furthermore, please have in mind that support threads are handled according to the license type and time of posting, so if it is an urgent issue, we suggest that you use a support ticket, which would be handled before a forum thread.
 
Regards,
Ivan Petrov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
PropertyGrid
Asked by
Kaven
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Kaven
Top achievements
Rank 1
ishara
Top achievements
Rank 1
Share this question
or