本文整理汇总了C#中System.Windows.Forms.CurrencyManager.GetItemProperties方法的典型用法代码示例。如果您正苦于以下问题:C# CurrencyManager.GetItemProperties方法的具体用法?C# CurrencyManager.GetItemProperties怎么用?C# CurrencyManager.GetItemProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.CurrencyManager
的用法示例。
在下文中一共展示了CurrencyManager.GetItemProperties方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIndex
/// <summary>
/// 获取数据项索引
/// </summary>
/// <param name="dataManager">数据管理对象</param>
/// <param name="propertyName">属性名称</param>
/// <param name="propertyValue">属性值</param>
/// <returns>返回指定属性名称的项的索引</returns>
public static int GetIndex(CurrencyManager dataManager, string propertyName, object propertyValue)
{
if (propertyValue == null) return -1;
PropertyDescriptorCollection props = dataManager.GetItemProperties();
PropertyDescriptor property = props.Find(propertyName, true);
if (property == null) throw new ArgumentNullException(propertyName);
var list = dataManager.List;
if ((list is IBindingList) && ((IBindingList)list).SupportsSearching)
{
return ((IBindingList)list).Find(property, propertyValue);
}
for (int i = 0; i < list.Count; i++)
{
object obj2 = property.GetValue(list[i]);
if (propertyValue.ToStringOrEmpty().Equals(obj2.ToStringOrEmpty()))
{
return i;
}
}
return -1;
}
示例2: GetValue
/// <summary>
/// 获取数据项的属性值
/// </summary>
/// <param name="dataManager">数据管理对象</param>
/// <param name="item">数据项</param>
/// <param name="propertyName">属性名称</param>
/// <returns>返回指定属性的值</returns>
public static object GetValue(CurrencyManager dataManager, object item, string propertyName)
{
if (item == null || propertyName == null || propertyName.Length == 0) return null;
try
{
PropertyDescriptor descriptor = dataManager != null ?
dataManager.GetItemProperties().Find(propertyName, true) :
TypeDescriptor.GetProperties(item).Find(propertyName, true);
if (descriptor != null)
{
item = descriptor.GetValue(item);
}
}
catch
{
return null;
}
return item;
}
示例3: CheckValidDataSource
protected void CheckValidDataSource (CurrencyManager value)
{
if (value == null) {
throw new ArgumentNullException ("CurrencyManager cannot be null");
}
if (property_descriptor == null) {
property_descriptor = value.GetItemProperties ()[mapping_name];
// Console.WriteLine ("mapping name = {0}", mapping_name);
// foreach (PropertyDescriptor prop in value.GetItemProperties ()) {
// Console.WriteLine (" + prop = {0}", prop.Name);
// }
if (property_descriptor == null)
throw new InvalidOperationException ("The PropertyDescriptor for this column is a null reference");
/*MonoTests.System.Windows.Forms.DataGridColumnStyleTest.GetColumnValueAtRow : System.InvalidOperationException : The 'foo' DataGridColumnStyle cannot be used because it is not associated with a Property or Column in the DataSource.*/
}
}
示例4: SetGridColumnStylesCollection
internal void SetGridColumnStylesCollection(CurrencyManager listManager) {
// when we are setting the gridColumnStyles, do not handle any gridColumnCollectionChanged events
gridColumns.CollectionChanged -= new CollectionChangeEventHandler(this.OnColumnCollectionChanged);
PropertyDescriptorCollection propCollection = listManager.GetItemProperties();
// we need to clear the relations list
if (relationsList.Count > 0)
relationsList.Clear();
Debug.Assert(propCollection != null, "propCollection is null: how that happened?");
int propCount = propCollection.Count;
for (int i = 0; i < propCount; i++) {
PropertyDescriptor prop = propCollection[i];
Debug.Assert(prop != null, "prop is null: how that happened?");
// do not take into account the properties that are browsable.
if (!prop.IsBrowsable)
continue;
if (PropertyDescriptorIsARelation(prop)) {
// relation
relationsList.Add(prop.Name);
}
else
{
// column
DataGridColumnStyle col = this.CreateGridColumn(prop, this.isDefaultTableStyle);
if (this.isDefaultTableStyle)
gridColumns.AddDefaultColumn(col);
else {
col.MappingName = prop.Name;
col.HeaderText = prop.Name;
gridColumns.Add(col);
}
}
}
// now we are able to handle the collectionChangeEvents
gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged);
}
示例5: SetRelationsList
internal void SetRelationsList(CurrencyManager listManager) {
PropertyDescriptorCollection propCollection = listManager.GetItemProperties();
Debug.Assert(!this.IsDefault, "the grid can set the relations only on a table that was manually added by the user");
int propCount = propCollection.Count;
if (relationsList.Count > 0)
relationsList.Clear();
for (int i = 0; i < propCount; i++) {
PropertyDescriptor prop = propCollection[i];
Debug.Assert(prop != null, "prop is null: how that happened?");
if (PropertyDescriptorIsARelation(prop)) {
// relation
relationsList.Add(prop.Name);
}
}
}
示例6: SetRelationsList
internal void SetRelationsList(CurrencyManager listManager)
{
PropertyDescriptorCollection itemProperties = listManager.GetItemProperties();
int count = itemProperties.Count;
if (this.relationsList.Count > 0)
{
this.relationsList.Clear();
}
for (int i = 0; i < count; i++)
{
PropertyDescriptor prop = itemProperties[i];
if (PropertyDescriptorIsARelation(prop))
{
this.relationsList.Add(prop.Name);
}
}
}
示例7: SetGridColumnStylesCollection
internal void SetGridColumnStylesCollection(CurrencyManager listManager)
{
this.gridColumns.CollectionChanged -= new CollectionChangeEventHandler(this.OnColumnCollectionChanged);
PropertyDescriptorCollection itemProperties = listManager.GetItemProperties();
if (this.relationsList.Count > 0)
{
this.relationsList.Clear();
}
int count = itemProperties.Count;
for (int i = 0; i < count; i++)
{
PropertyDescriptor prop = itemProperties[i];
if (prop.IsBrowsable)
{
if (PropertyDescriptorIsARelation(prop))
{
this.relationsList.Add(prop.Name);
}
else
{
DataGridColumnStyle column = this.CreateGridColumn(prop, this.isDefaultTableStyle);
if (this.isDefaultTableStyle)
{
this.gridColumns.AddDefaultColumn(column);
}
else
{
column.MappingName = prop.Name;
column.HeaderText = prop.Name;
this.gridColumns.Add(column);
}
}
}
}
this.gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged);
}
示例8: PairTableStylesAndGridColumns
private void PairTableStylesAndGridColumns(CurrencyManager lm, DataGridTableStyle gridTable, bool forceColumnCreation)
{
PropertyDescriptorCollection itemProperties = lm.GetItemProperties();
GridColumnStylesCollection gridColumnStyles = gridTable.GridColumnStyles;
if (!gridTable.IsDefault && (string.Compare(lm.GetListName(), gridTable.MappingName, true, CultureInfo.InvariantCulture) == 0))
{
if ((gridTable.GridColumnStyles.Count == 0) && !base.DesignMode)
{
if (forceColumnCreation)
{
gridTable.SetGridColumnStylesCollection(lm);
}
else
{
gridTable.SetRelationsList(lm);
}
}
else
{
for (int i = 0; i < gridColumnStyles.Count; i++)
{
gridColumnStyles[i].PropertyDescriptor = null;
}
for (int j = 0; j < itemProperties.Count; j++)
{
DataGridColumnStyle style = gridColumnStyles.MapColumnStyleToPropertyName(itemProperties[j].Name);
if (style != null)
{
style.PropertyDescriptor = itemProperties[j];
}
}
gridTable.SetRelationsList(lm);
}
}
else
{
gridTable.SetGridColumnStylesCollection(lm);
if ((gridTable.GridColumnStyles.Count > 0) && (gridTable.GridColumnStyles[0].Width == -1))
{
this.InitializeColumnWidths();
}
}
}