我在Devexperess网格控件列中有一个组合框编辑控件。它填充Itemssource集合中给定的值,基于Row值加载初始值,但是不允许选择一个值。 用户应该能够选择值。我的目标是读取选定的行和过程值。
<dxg:GridControl ItemsSource="{Binding Wells}"
AutoGenerateColumns="None"
EnableSmartColumnsGeneration="True"
SelectionMode="Cell">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Name"
FieldName="Name"
Width="150"
Fixed="Left">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBox HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="Transparent"
Text="{Binding RowData.Row.Name, Mode=TwoWay}" />
</Grid>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
<dxg:GridColumn Header="TypeCurve"
Width="130"
ReadOnly="True"
Binding="{Binding TypeCurve}"
FilterPopupMode="CheckedList"
ColumnFilterMode="DisplayText"
FieldName="TypeCurve"
IsSmart="True">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ComboBoxEdit x:Name="PART_Editor"
AutoComplete="True"
ShowBorder="False"
BorderThickness="0"
ItemsSource="{Binding DataContext.TypeCurves,ElementName=mainWindow}"
DisplayMember="Name"
ImmediatePopup="True">
</dxe:ComboBoxEdit>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
</dxg:GridControl>
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool && ((bool)value))
return Visibility.Visible;
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class BaseClass : INotifyPropertyChanged
{
#region NotifyChanged
public new event PropertyChangedEventHandler PropertyChanged;
protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
protected virtual void NotifyPropertyChanged<T>(Expression<Func<T>> expression)
{
var handler = PropertyChanged;
if (handler == null)
return;
var propertyName = PropertyOf(expression).Name;
handler(this, new PropertyChangedEventArgs(propertyName));
}
private static PropertyInfo PropertyOf<T>(Expression<Func<T>> expression)
{
var memberExpr = expression.Body as MemberExpression;
// If the method gets a lambda expression that is not a member access,
// for example, () => x + y, an exception is thrown
if (memberExpr == null)
throw new ArgumentException("Expression \"" + expression +
"\" is not a valid member expression.");
var property = memberExpr.Member as PropertyInfo;
if (property == null)
throw new ArgumentException("Expression \"" + expression +
"\" does not reference a property.");
return property;
}
/// <summary>
/// Triggers property change notification on the caller.
/// Without passing the property Name
/// </summary>
/// <param name="propertyName"></param>
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
public class InventoryWell : BaseClass
{
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; NotifyPropertyChanged(); }
}
private LookupValue _TypeCurve;
public LookupValue TypeCurve
{
get { return _TypeCurve; }
set { _TypeCurve = value; NotifyPropertyChanged(); }
}
}
public class myVM : BaseClass
{
public myVM()
{
Wells = new ObservableCollection<InventoryWell>();
TypeCurves = new ObservableCollection<LookupValue>();
TypeCurves.Add(new LookupValue() { Name = "Look Up 0" });
TypeCurves.Add(new LookupValue() { Name = "Look Up 1" });
TypeCurves.Add(new LookupValue() { Name = "Look Up 2" });
TypeCurves.Add(new LookupValue() { Name = "Look Up 3" });
TypeCurves.Add(new LookupValue() { Name = "Look Up 4" });
TypeCurves.Add(new LookupValue() { Name = "Look Up 5" });
InventoryWell x = new InventoryWell() { Name = "Well 1"};
x.TypeCurve = TypeCurves[0];
Wells.Add(x);
x = new InventoryWell() { Name = "Well 2"};
x.TypeCurve = TypeCurves[0];
Wells.Add(x);
x = new InventoryWell() { Name = "Well 3"};
x.TypeCurve = TypeCurves[1];
Wells.Add(x);
x = new InventoryWell() { Name = "Well 4"};
x.TypeCurve = TypeCurves[1];
Wells.Add(x);
x = new InventoryWell() { Name = "Well 5"};
x.TypeCurve = TypeCurves[1];
Wells.Add(x);
}
ObservableCollection<InventoryWell> _Wells;
public ObservableCollection<InventoryWell> Wells
{
get { return _Wells; }
set { _Wells = value; NotifyPropertyChanged(); }
}
private ObservableCollection<LookupValue> _TypeCurves;
public ObservableCollection<LookupValue> TypeCurves
{
get { return _TypeCurves; }
set { _TypeCurves = value; NotifyPropertyChanged(); }
}
}
public class LookupValue : BaseClass
{
public LookupValue()
{
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; NotifyPropertyChanged(); }
}
public override string ToString()
{
return Name;
}
}
任何人都可以帮忙。