Tuesday, March 9, 2010

Infragistics - Working with 2 XamComboEditors in XamDataGrid


Recently I had to work on a sample where I had to populate the combo box values on a datagrid column field based on the selection from the first column values. I had 2 XamComboEditors in a XamDataGrid on the same row. When the first XamComboEditor changes its value, the second XamComboEditor should refresh its item source to repopulate the values based on the first comboEditor selection.
I worked on a sample application with Country/ State scenario, where the states options are based on the country selection.
XAML code
<igdp:UnboundField Name="Country" BindingPath="Country.Name" Label="Country" Column="0" IsScrollTipField="True">
    <igdp:UnboundField.Settings>
        <igdp:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}">
            <igdp:FieldSettings.EditorStyle>
                <Style TargetType="{x:Type igEditors:XamComboEditor}">
                    <Setter Property="DisplayMemberPath" Value="Name" />
                    <Setter Property="ValuePath" Value="Id" />
                    <Setter Property="ItemsSource" Value="{Binding Path=DataContext.CountryCollection,
                        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
                    <Setter Property="ValueType" Value="{x:Type entities:Country}" />
                    <Setter Property="IsAlwaysInEditMode" Value="False" />
                    <Setter Property="IsEditable" Value="False" />
                    <Setter Property="DropDownButtonDisplayMode" Value="OnlyInEditMode" />
                    <EventSetter Event="SelectedItemChanged" Handler="OnCountrySelectionChanged" />
                Style>
            igdp:FieldSettings.EditorStyle>
        igdp:FieldSettings>
    igdp:UnboundField.Settings>
igdp:UnboundField>
<igdp:UnboundField Name="State" BindingPath="State.Name" Label="State" Column="1">
    <igdp:UnboundField.Settings>
        <igdp:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}">
            <igdp:FieldSettings.EditorStyle>
                <Style TargetType="{x:Type igEditors:XamComboEditor}">
                    <Setter Property="DisplayMemberPath" Value="Name" />
                    <Setter Property="ValuePath" Value="Id" />
                    <Setter Property="ValueType" Value="{x:Type entities:State}" />
                    <Setter Property="IsAlwaysInEditMode" Value="False" />
                    <Setter Property="IsEditable" Value="False" />
                    <Setter Property="DropDownButtonDisplayMode" Value="OnlyInEditMode" />
                Style>
            igdp:FieldSettings.EditorStyle>
        igdp:FieldSettings>
    igdp:UnboundField.Settings>
igdp:UnboundField>
Code behind file
void OnCountrySelectionChanged(object sender, RoutedEventArgs e)
{
    DataRecord dataRecord = (DataRecord)grdSample.ActiveRecord;
    CellValuePresenter countryCellValuePresenter = CellValuePresenter.FromCell(dataRecord.Cells[0]);
    XamComboEditor countryComboEditor = countryCellValuePresenter.Editor as XamComboEditor;
    if (countryComboEditor == null) return;
    Country country = countryComboEditor.SelectedItem as Country;
   
    CellValuePresenter stateCellValuePresenter = CellValuePresenter.FromCell(dataRecord.Cells[1]);
    XamComboEditor stateComboEditor = stateCellValuePresenter.Editor as XamComboEditor;
    if (stateComboEditor == null) return;
    var states = Factory.GetStateByCountry(country.Name);
    stateComboEditor.ItemsSource = states;
    stateComboEditor.SelectedItem = states[0];
}

Thursday, March 4, 2010

Clear SQL Server Cache


While working on performance tuning sql queries or procs, the query which took a considerable amount of time to execute the first time will take very less time to execute the second time. The reason behind this was the data getting cached and sql server uses this cached data to publish the results.
To free this cached data use the commands DBCC DROPCLEANBUFFERS and DBCC FREEPROCCACHE.
DBCC DROPCLEANBUFFERS clears all data from the cache. Any data loaded into the buffer cache due to the prior execution of a query is removed.
DBCC FREEPROCCACHE clears the stored procedure cache.