Answer the question
In order to leave comments, you need to log in
WPF form not showing saved data in DataGridComboBoxColumn elements when opening?
Hello!
I have a datagrid form like this:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Items}" SelectionMode="Single" SelectedItem="{Binding SelectedItem}" Grid.ColumnSpan="5" Grid.Row="1" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserAddRows="False" RowDetailsVisibilityMode="Visible">
<DataGrid.Columns>
<DataGridComboBoxColumn x:Name="kindsEl" Header="Вид РК:" Width="25*" TextBinding="{Binding Kind.KindName, Mode=TwoWay}" SelectedValueBinding="{Binding Kind, Mode=TwoWay}" DisplayMemberPath="{Binding Kind.KindName, Mode=TwoWay}">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}">
<EventSetter Event="SelectionChanged" Handler="SomeSelectionChanged" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
<DataGridComboBoxColumn x:Name="themeEl" Header="Тема:" Width="25*" SelectedItemBinding="{Binding Theme}" TextBinding="{Binding Theme.FieldName}" />
<DataGridComboBoxColumn x:Name="startEl" Header="Дата от:" Width="25*" SelectedItemBinding="{Binding Start}" TextBinding="{Binding Start.FieldName}" />
<DataGridComboBoxColumn x:Name="endEl" Header="Дата до:" Width="25*" SelectedItemBinding="{Binding End}" TextBinding="{Binding End.FieldName}"/>
</DataGrid.Columns>
</DataGrid>
class CalendarMetaItem : INotifyPropertyChanged
{
private KindModel kind;
private FieldModel theme;
private FieldModel start;
private FieldModel end;
public KindModel Kind
{
get
{
return this.kind;
}
set
{
this.kind = value;
NotifyPropertyChanged();
}
}
public FieldModel Theme
{
get
{
return this.theme;
}
set
{
this.theme = value;
NotifyPropertyChanged();
}
}
public FieldModel Start
{
get
{
return this.start;
}
set
{
this.start = value;
NotifyPropertyChanged();
}
}
public FieldModel End
{
get
{
return this.end;
}
set
{
this.end = value;
NotifyPropertyChanged();
}
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
class KindModel
{
public string TypeId { get; set; }
public string KindName { get; set; }
public string KindId { get; set; }
public string ParentKindId { get; set; }
public int Level { get; set; }
public override string ToString()
{
var tab = "";
for (int i = 0; i < Level; i++)
{
tab += " ";
}
return tab + KindName;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question