Click here to Skip to main content
15,896,154 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
SledgeHammer018-Apr-11 7:59
SledgeHammer018-Apr-11 7:59 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
eddieangel8-Apr-11 9:47
eddieangel8-Apr-11 9:47 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
SledgeHammer018-Apr-11 10:18
SledgeHammer018-Apr-11 10:18 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
eddieangel8-Apr-11 10:29
eddieangel8-Apr-11 10:29 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
SledgeHammer018-Apr-11 10:52
SledgeHammer018-Apr-11 10:52 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
eddieangel8-Apr-11 11:43
eddieangel8-Apr-11 11:43 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
SledgeHammer018-Apr-11 12:03
SledgeHammer018-Apr-11 12:03 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
eddieangel8-Apr-11 12:07
eddieangel8-Apr-11 12:07 
Perhaps additional code will help to clarify.

public ObservableCollection<Property> AllProperties { get; private set; }
    public ObservableCollection<PropertyState> PropertyStates { get; private set; }
    public ObservableCollection<StreetSuffix> StreetSuffixes { get; private set; }
    public ICommand SaveCommand { get { return new RelayCommand(param => Save(), CanSaveExecute); } }
    public Property SelectedItem
    {
        get { return _selectedItem; }
        set
        {

            if (value == null)
                return;

            _selectedItem = value;
            OnPropertyChanged("SelectedItem");
        }
    }
    public StreetSuffix SelectedSuffix
    {
        get { return _selectedSuffix; }
        set
        {
            if (value == null)
                return;

            _selectedSuffix = value;
            OnPropertyChanged("SelectedSuffix");
            OnPropertyChanged("SelectedItem");
        }
    }

    #endregion

    #region private helpers

    private void LoadProperties()
    {
        var query = _db.Properties.Where(p => p.claimId == _claimId && p.active);
        AllProperties = new ObservableCollection<Property>(query.ToList());
    }

    private void LoadStreetSuffixes()
    {
        var query = _db.StreetSuffixes;
        StreetSuffixes = new ObservableCollection<StreetSuffix>(query.ToList());
    }

    private void LoadStates()
    {
        var query = _db.PropertyStates;
        PropertyStates = new ObservableCollection<PropertyState>(query.ToList());
    }


And the view:

<DataGrid
            ItemsSource="{Binding AllProperties}"
            AutoGenerateColumns="False"
            SelectedItem="{Binding SelectedItem}"
            GridLinesVisibility="Horizontal"
            CanUserDeleteRows="False"
            Grid.Row="0"
            RowStyle="{StaticResource RowStyle}">
            
            <DataGrid.RowValidationRules>
                <local:RowDataInfoValidationRule
                    ValidationStep="UpdatedValue" />
            </DataGrid.RowValidationRules>
            
            <DataGrid.CellStyle>
                <Style
                    TargetType="{x:Type DataGridCell}">
                    <Style.Triggers>
                        <Trigger
                            Property="IsSelected"
                            Value="True">
                            <Setter
                                Property="Foreground"
                                Value="WhiteSmoke" />
                            <Setter
                                Property="Background"
                                Value="LightSlateGray" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>
            
            <DataGrid.Columns>
                <DataGridTextColumn
                    Header="Number"
                    Width="54">
                    <DataGridTextColumn.Binding>
                        <Binding
                            Path="number">
                            <Binding.ValidationRules>
                                <local:CellDataInfoValidationRule
                                    ValidationStep="UpdatedValue" />
                            </Binding.ValidationRules>
                        </Binding>
                    </DataGridTextColumn.Binding>
                </DataGridTextColumn>
                <DataGridTemplateColumn

                    Header="Direction"
                    Width="58">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock
                                Text="{Binding direction}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox
                                Text="{Binding direction, ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn
                    Header="Street Name"
                    Width="77">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock
                                Text="{Binding street}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox
                                Text="{Binding street, ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn
                    Header="Type"
                    Width="55">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock
                                Text="{Binding StreetSuffix.abbreviation}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                                <ComboBox
                                    ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.StreetSuffixes}"
                                    DisplayMemberPath="name"
                                    SelectedValuePath="id"
                                    SelectedValue="{Binding suffixId}"
                                    SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.SelectedSuffix}" />
                            </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn
                    Width="55"
                    Binding="{Binding unit}"
                    Header="Unit" />
                <DataGridTemplateColumn
                    Header="City"
                    Width="75">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock
                                Text="{Binding city}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox>
                                <Binding
                                    Path="city">
                                    <Binding.ValidationRules>
                                        <local:CellDataInfoValidationRule
                                            ValidationStep="UpdatedValue" />
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn
                    Header="State"
                    Width="60">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock
                                Text="{Binding PropertyState.name}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox
                                ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.PropertyStates, ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"
                                DisplayMemberPath="name"
                                SelectedValuePath="id"
                                SelectedValue="{Binding stateId}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn
                    Header="Zip Code"
                    Width="60">
                    <DataGridTextColumn.Binding>
                        <Binding
                            Path="zip">
                            <Binding.ValidationRules>
                                <local:CellDataInfoValidationRule
                                    ValidationStep="UpdatedValue" />
                            </Binding.ValidationRules>
                        </Binding>
                    </DataGridTextColumn.Binding>
                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>


So "Selected Item" refers to the selected item of the datagrid, not the selected item of the combobox. Is that my issue? That I need to bind to an ancestor?
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
SledgeHammer018-Apr-11 12:18
SledgeHammer018-Apr-11 12:18 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
eddieangel8-Apr-11 12:30
eddieangel8-Apr-11 12:30 
QuestionWhat Is A HitTest? Pin
Kevin Marois7-Apr-11 5:35
professionalKevin Marois7-Apr-11 5:35 
AnswerRe: What Is A HitTest? Pin
Pete O'Hanlon7-Apr-11 6:27
mvePete O'Hanlon7-Apr-11 6:27 
GeneralRe: What Is A HitTest? Pin
Kevin Marois7-Apr-11 6:32
professionalKevin Marois7-Apr-11 6:32 
GeneralRe: What Is A HitTest? Pin
Pete O'Hanlon7-Apr-11 6:38
mvePete O'Hanlon7-Apr-11 6:38 
GeneralRe: What Is A HitTest? Pin
Kevin Marois7-Apr-11 6:40
professionalKevin Marois7-Apr-11 6:40 
GeneralRe: What Is A HitTest? Pin
Pete O'Hanlon7-Apr-11 6:51
mvePete O'Hanlon7-Apr-11 6:51 
GeneralRe: What Is A HitTest? Pin
Kevin Marois7-Apr-11 6:52
professionalKevin Marois7-Apr-11 6:52 
GeneralRe: What Is A HitTest? Pin
Pete O'Hanlon7-Apr-11 8:29
mvePete O'Hanlon7-Apr-11 8:29 
GeneralRe: What Is A HitTest? Pin
Kevin Marois7-Apr-11 8:45
professionalKevin Marois7-Apr-11 8:45 
JokeRe: What Is A HitTest? Pin
Mycroft Holmes7-Apr-11 14:40
professionalMycroft Holmes7-Apr-11 14:40 
GeneralRe: What Is A HitTest? Pin
Pete O'Hanlon7-Apr-11 21:51
mvePete O'Hanlon7-Apr-11 21:51 
GeneralRe: What Is A HitTest? Pin
Mycroft Holmes7-Apr-11 22:14
professionalMycroft Holmes7-Apr-11 22:14 
QuestionMessage: The name already exists in the tree: Pin
Vimalsoft(Pty) Ltd6-Apr-11 23:42
professionalVimalsoft(Pty) Ltd6-Apr-11 23:42 
AnswerRe: Message: The name already exists in the tree: Pin
Abhinav S7-Apr-11 18:14
Abhinav S7-Apr-11 18:14 
GeneralRe: Message: The name already exists in the tree: [modified] Pin
Vimalsoft(Pty) Ltd7-Apr-11 18:48
professionalVimalsoft(Pty) Ltd7-Apr-11 18:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.