本文整理汇总了C#中System.Windows.Forms.BindingSource.GetItemProperties方法的典型用法代码示例。如果您正苦于以下问题:C# BindingSource.GetItemProperties方法的具体用法?C# BindingSource.GetItemProperties怎么用?C# BindingSource.GetItemProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.BindingSource
的用法示例。
在下文中一共展示了BindingSource.GetItemProperties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetDataSource
public void SetDataSource(BindingSource source)
{
tblMain.Controls.Clear();
tblMain.RowStyles.Clear();
tblMain.RowCount = 0;
var dataTypeArray = Enum.GetValues(typeof(QueryParameter.DataType)).OfType<QueryParameter.DataType>().ToArray();
var props = source.GetItemProperties(null).OfType<PropertyDescriptor>()
.Where(p => Filter == null || Filter.Contains(p))
.OrderBy(p => p.DisplayName ?? p.Name)
.ToArray();
foreach (var prop in props)
{
tblMain.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tblMain.RowCount += 1;
var currRow = tblMain.RowCount - 1;
var lbl = new Label();
lbl.AutoSize = true;
lbl.Text = prop.DisplayName ?? prop.Name;
lbl.Anchor = AnchorStyles.Left;
tblMain.Controls.Add(lbl, 0, currRow);
var currProp = prop as QueryParamDescriptor;
if (currProp != null)
{
var box = new ComboBox();
box.Anchor = AnchorStyles.Left;
box.DropDownStyle = ComboBoxStyle.DropDownList;
box.DataSource = Enum.GetValues(typeof(QueryParameter.DataType));
tblMain.Controls.Add(box, 1, currRow);
_initialValues.Add(Array.IndexOf(dataTypeArray, currProp.Param.Type));
box.SelectedIndexChanged += (s, e) =>
{
if (!_isLoaded)
return;
tblMain.Controls.Remove(tblMain.GetControlFromPosition(2, currRow));
var newValue = (QueryParameter.DataType)((ComboBox)s).SelectedValue;
currProp.Param.Type = newValue;
switch (newValue)
{
case QueryParameter.DataType.Boolean:
currProp.SetValue(source.Current, default(bool));
AddControl(source, currProp, typeof(bool), currRow);
break;
case QueryParameter.DataType.DateTime:
currProp.SetValue(source.Current, default(DateTime));
AddControl(source, currProp, typeof(DateTime), currRow);
break;
case QueryParameter.DataType.Decimal:
currProp.SetValue(source.Current, default(decimal));
AddControl(source, currProp, typeof(decimal), currRow);
break;
case QueryParameter.DataType.Integer:
currProp.SetValue(source.Current, default(long));
AddControl(source, currProp, typeof(long), currRow);
break;
default:
currProp.SetValue(source.Current, default(string));
AddControl(source, currProp, typeof(string), currRow);
break;
}
};
}
AddControl(source, prop, null, currRow);
}
}