2 öğe içeren bir özellik ızgaram var. Ülke & Şehirler. Veritabanında 1 tablo var: LocationId, Title, ParentId öğesini kaydeden CountryCityTable. Ülkeler için parentId = 0 ve şehirler için countryid.WinG biçiminde başka bir öğe değiştiğinde propertygrid öğesi değerlerini nasıl güncelleyebilirim?
Mülk kılavuzumda bunları kullanıyorum ve 2 combobox öğesinde gösteriyorum. kodumu bakınız: Kullanıcı propertygrid ülke unvanını değişti
namespace ProGrid
{
public class KeywordProperties
{
[TypeConverter(typeof(CountryLocationConvertor))]
public string CountryNames { get; set; }
[TypeConverter(typeof(CityLocationConvertor))]
public string CityNames { get; set; }
}
}
Ve
namespace ProGrid
{
public class CountryLocationConvertor : StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
HumanRoles Db = new HumanRoles();
List<LocationsFieldSet> Items = new List<LocationsFieldSet>();
Items = Db.LoadLocations(0,0);
string[] LocationItems = new string[Items.Count];
int count = 0;
foreach (LocationsFieldSet Item in Items)
{
LocationItems[count] = Item.Title;
count++;
}
return new StandardValuesCollection(LocationItems);
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;//false : If you want the user to be able to type in a value that is not in the drop-down list.
}
}
public class CityLocationConvertor : StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
HumanRoles Db = new HumanRoles();
List<LocationsFieldSet> Items = new List<LocationsFieldSet>();
Items = Db.LoadLocations(1,20);
string[] LocationItems = new string[Items.Count];
int count = 0;
foreach (LocationsFieldSet Item in Items)
{
LocationItems[count] = Item.Title;
count++;
}
return new StandardValuesCollection(LocationItems);
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}
}
}
Ve
KeywordProperties Kp = new KeywordProperties();
myPropertyGrid.SelectedObject = Kp;
Şimdi, istediğim, güncellenmiş şehirler listesi (sadece şehirler gösterdiğini parentid Bunlar = countryid). Seçilen ülke kimliğine;
Ayrıca benim sınıfımda nasıl benim kodunda Sayı 20 (Db.LoadLocations (1,20)) değiştirebilirim?
Teşekkür ederiz.
[RefreshProperties] özniteliğini uygulayın. –
Lütfen kodumu bu özellik ile değiştirin. Teşekkürler. –
Hans dediği gibi, bu özellik güzel çalışıyor ve çok temiz. Ayrıca daha fazla ayrıntı için kontrol edin http://stackoverflow.com/a/4955653/586754 –