Propertygrid

R

Redivivus

Hi

Ho to use dropdown in propertygrid with values from database?

Lets say i have table ITEMS
and columns ID, NAME

Now i want to select id, name from items
and display those values in dropdown of my propertygrid


Best regards;

Mex
 
V

VisualHint

The mentioned article is a good start, however, instead of relying on
a global variable to hold the possible values for the dropdown box, I
would use the Instance property passed through the
ITypeDescriptorContext. The term "context" really means that you can
get your values from the current context, i.e. the currently selected
target instance of the PropertyGrid. I wrote an article not so long
ago which can give you some clues too (http://www.visualhint.com/
index.php/blog/post/
how_to_setup_a_truly_dynamic_combobox_in_the_propertygrid/)

Best regards,

Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List[/
url]
Free [url="http://www.visualhint.com/index.php/propertygrid_mfc/?
utm_source=msdn&utm_medium=signature&utm_campaign=spgmfc" title="Free
MFC PropertyGrid"]PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker[/url]
 
V

VisualHint

Hello Mex,

The mentioned article is a good start, however, instead of relying on
a global variable to hold the possible values for the dropdown box, I
would use the Instance property passed through the
ITypeDescriptorContext. The term "context" really means that you can
get your values from the current context, i.e. the currently selected
target instance of the PropertyGrid. I wrote an article not so long
ago which can give you some clues too (http://www.visualhint.com/
index.php/blog/post/
how_to_setup_a_truly_dynamic_combobox_in_the_propertygrid/)

(sorry for the repost, the signature was awful)

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart FieldPackEditor.Net / DateTimePicker replacement (http://
www.visualhint.com/index.php/fieldpackeditor)
Home of Smart PropertyGrid for .Net and MFC (http://www.visualhint.com/
index.php/propertygrid)
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com


The mentioned article is a good start, however, instead of relying on
a global variable to hold the possible values for the dropdown box, I
would use the Instance property passed through the
ITypeDescriptorContext. The term "context" really means that you can
get your values from the current context, i.e. the currently selected
target instance of the PropertyGrid. I wrote an article not so long
ago which can give you some clues too (http://www.visualhint.com/
index.php/blog/post/
how_to_setup_a_truly_dynamic_combobox_in_the_propertygrid/)

Best regards,

Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List[/
url]
Free [url="http://www.visualhint.com/index.php/propertygrid_mfc/?
utm_source=msdn&utm_medium=signature&utm_campaign=spgmfc" title="Free
MFC PropertyGrid"]PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker

hi,
below is a useful link

cheers !
Husam Al-A'arajwww.aaraj.net
[/url]
http://www.propertygridresourcelist.com" title="Free resources for the Microsoft PropertyGrid
 
M

Mex

Ok i know now hot to use simple combobox in propertygrid
(see code below)
but how to add items with value
Mother=1,Sister=2
and when user select item from combobox i get valuemember not displaymember?


Mex


public class FamilyMember : Component
{

private string relation = "Unknown";

[TypeConverter(typeof(RelationConverter)),Category("Details")]
public string Relation
{
get { return relation; }
set { this.relation = value; }
}
}

internal class RelationConverter : StringConverter
{

private static StandardValuesCollection defaultRelations =
new StandardValuesCollection(
new string[]{"Mother", "Father", "Sister",
"Brother", "Daughter", "Son",
"Aunt", "Uncle", "Cousin"});


public override bool GetStandardValuesSupported(
ITypeDescriptorContext context)
{
return true;
}



public override bool GetStandardValuesExclusive(
ITypeDescriptorContext context)
{
// returning false here means the property will
// have a drop down and a value that can be manually
// entered.
return true;
}

public override StandardValuesCollection GetStandardValues(
ITypeDescriptorContext context)
{
return defaultRelations;
}
}
 
V

VisualHint

Hello Mex,

instead of using strings in your standard values, use objects that
store an integer but whose TypeConverter returns the string you want
for the integer. This is what my previously mentioned article
explains.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart FieldPackEditor.Net / DateTimePicker replacement (http://
www.visualhint.com/index.php/fieldpackeditor)
Home of Smart PropertyGrid for .Net and MFC (http://www.visualhint.com/
index.php/propertygrid)
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com



Ok i know now hot to use simple combobox inpropertygrid
(see code below)
but how to add items with value
Mother=1,Sister=2
and when user select item from combobox i get valuemember not displaymember?

Mex

public class FamilyMember : Component
{

private string relation = "Unknown";

[TypeConverter(typeof(RelationConverter)),Category("Details")]
public string Relation
{
get { return relation; }
set { this.relation = value; }
}
}

internal class RelationConverter : StringConverter
{

private static StandardValuesCollection defaultRelations =
new StandardValuesCollection(
new string[]{"Mother", "Father", "Sister",
"Brother", "Daughter", "Son",
"Aunt", "Uncle", "Cousin"});

public override bool GetStandardValuesSupported(
ITypeDescriptorContext context)
{
return true;
}

public override bool GetStandardValuesExclusive(
ITypeDescriptorContext context)
{
// returning false here means the property will
// have a drop down and a value that can be manually
// entered.
return true;
}

public override StandardValuesCollection GetStandardValues(
ITypeDescriptorContext context)
{
return defaultRelations;
}
}

Ho to use dropdown inpropertygridwith values from database?
Lets say i have table ITEMS
and columns ID, NAME
Now i want to select id, name from items
and display those values in dropdown of mypropertygrid
Best regards;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top