我在做Silverlight 4 App。
我有5列的网格控制,我将ComboBoxEditor放在一列中。
<dxg:GridControl x:Name="grid_currentillnes">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Complaints" Header="Complaints/Disease" />
<dxg:GridColumn FieldName="Duration" Header="Duratiion" />
<dxg:GridColumn FieldName="Period" Header="Period" />
<dxg:GridColumn Header="Treatment" FieldName="Treatment">
<dxg:GridColumn.EditSettings>
<dxe:ComboBoxEditSettings x:Name="cmbx_treatmenttype" PopupMaxHeight="150" DisplayMember="Treatment" ValueMember="Treatment" />
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
<dxg:GridColumn Header="Details" FieldName="Details" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView Name="tableView4" ShowGroupPanel="False" NewItemRowPosition="Top" NavigationStyle="Cell" />
</dxg:GridControl.View>
</dxg:GridControl>
我希望得到组合框编辑器的选择更改事件,但不存在此类事件。这样做了怎么办?
答案 0 :(得分:6)
当View处于编辑模式时,一次只有一个编辑器。显示此编辑器后,视图将触发GridViewBase.ShownEditor事件。因此,您可以使用此事件订阅活动编辑器(ComboBoxEdit.SelectedIndexChanged)的任何事件(例如GridViewBase.ActiveEditor)。要取消订阅该活动,您可以使用GridViewBase.HiddenEditor:
tableView3.ShownEditor += new EditorEventHandler(tableView3_ShownEditor);
tableView3.HiddenEditor += new EditorEventHandler(tableView3_HiddenEditor);
//...
void tableView3_ShownEditor(object sender, EditorEventArgs e) {
if(e.Column.FieldName == "Treatment") {
((ComboBoxEdit)tableView3.ActiveEditor).SelectedIndexChanged += ComboBoxEdit_SelectedIndexChanged;
}
}
void tableView3_HiddenEditor(object sender, EditorEventArgs e) {
if(e.Column.FieldName == "Treatment") {
((ComboBoxEdit)tableView3.ActiveEditor).SelectedIndexChanged -= ComboBoxEdit_SelectedIndexChanged;
}
}
void ComboBoxEdit_SelectedIndexChanged(object sender, RoutedEventArgs e) {
// do something
}