Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
325
Deselect records on margin click?
posted

Hello,

 

We're trying to deselect all selected records when the user clicks anything but a record.

 

For example, in the attached image, if the user clicks the circled area, the parent record ("Biography") is selected. We would like to deselect all records when this happens.

 

Any ideas?

 

Thanks,

Matt

  • 69686
    Suggested Answer
    posted

    Hello Matt,

    You can try handling the PreviewMouseLeftButtonDown event of the XamDataGrid and see if you can find a DataRecordCellArea element. If none is found, you can deselect all records, something like this:

    void xamDataGrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)

            {

                DataRecordCellArea area = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject,

                    typeof(DataRecordCellArea), false) as DataRecordCellArea;

                if (area == null)

                    xamDataGrid1.SelectedItems.Records.Clear();

            }

    • 325
      posted in reply to John Doe

      Thanks for the response,

      I have tried what you provided, also by just using "xamDataGrid1.SelectedItems.Records.Clear();" in a button.

      Both seem to not work.

      Thanks,

      Matt.

      • 69686
        posted in reply to Matt

        Matt,

        I did test this and it was working correctly. Can you please provide the sample that you are using and this is not having the desired effect?

        Thanks,

        Alex

        • 325
          posted in reply to John Doe

          When I click the area mentioned above it still selects a parent  record or does not deselect an item.

          For some reason when a member is clicked, "dgLeft.SelectedItems.Records" is empty. even when I did not apply your code.

                  <igDP:XamDataGrid
                      InitializeRecord="xamDataGrid1_InitializeRecord"
                      RecordExpanding="xamDataGrid1_RecordExpanding"
                      RecordExpanded="xamDataGrid1_RecordExpanded"
                      MouseDown="dgLeft_MouseDown"
                      RecordsInViewChanged="dgLeft_RecordsInViewChanged"
                      Margin="12,52.5,259,12"
                      x:Name="dgLeft"
                      GroupByAreaLocation="None"
                      ScrollingMode="Immediate"
                      PreviewMouseMove="dgLeft_PreviewMouseMove"
                      PreviewMouseLeftButtonDown="dgLeft_PreviewMouseLeftButtonDown"
                      MouseDoubleClick="xamDataGrid1_MouseDoubleClick"
                      RecordLoadMode="LoadOnDemand"
                      SnapsToDevicePixels="True"
                      AllowDrop="True">
                      <igDP:XamDataGrid.FieldSettings>
                          <igDP:FieldSettings
                              AllowEdit="False"
                              AllowGroupBy="False"
                              AllowResize="False"
                              AllowSummaries="False"
                              CellClickAction="SelectRecord" />
                      </igDP:XamDataGrid.FieldSettings>
                      <igDP:XamDataGrid.FieldLayouts>
                          <igDP:FieldLayout>
                              <igDP:FieldLayout.Fields>
                                  <igDP:Field Name="Name">
                                      <igDP:Field.Settings>
                                          <igDP:FieldSettings CellValuePresenterStyle="{StaticResource folderCell}" CellWidth="250" />
                                      </igDP:Field.Settings>
                                  </igDP:Field>
                                  <igDP:Field Name="ID" Visibility="Collapsed" />
                                  <igDP:Field Name="ParentID" Visibility="Collapsed" />
                                  <igDP:Field Name="IsFolder" Visibility="Collapsed" />
                                  <igDP:Field Name="FirstSeen" Visibility="Collapsed" />
                                  <igDP:Field Name="IsAdded" Visibility="Collapsed" />
                                  <igDP:Field Name="HasAddedChildren" Visibility="Collapsed" />
                              </igDP:FieldLayout.Fields>
                          </igDP:FieldLayout>
                      </igDP:XamDataGrid.FieldLayouts>
                      <igDP:XamDataGrid.FieldLayoutSettings>
                          <igDP:FieldLayoutSettings AutoGenerateFields="True" LabelLocation="Hidden" HeaderPlacement="OnTopOnly" SelectionTypeRecord="Default" RecordSelectorLocation="None" ExpansionIndicatorDisplayMode="CheckOnDisplay" />
                      </igDP:XamDataGrid.FieldLayoutSettings>
                  </igDP:XamDataGrid>

           

                          DataRecordCellArea area = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject,
              typeof(DataRecordCellArea), false) as DataRecordCellArea;

                          if (area == null)
                              dgLeft.SelectedItems.Records.Clear();

           

          Thanks,

          Matt

          • 69686
            posted in reply to Matt

            Matt,

            Actually, the are that you have circled is only for the XamDataGrid, and no other elements are there. You can modify this to search for any RecordPresenter (Label,DataRecord,etc). If none is found, you can call a ClearAllCommand. What you will see is the ActiveRecord remaining - it will look as selected, but the SelectedItems collection will be empty. If you want to go around this, you can set the Active Record to null, so that nothing appears selected. Here is the code snippet:

            void xamDataGrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)

                    {

                        RecordPresenter area = Infragistics.Windows.Utilities.GetAncestorFromType(

                            e.OriginalSource as DependencyObject,

                            typeof(RecordPresenter), true) as RecordPresenter;

                        if (area == null)

                        {

                            xamDataGrid1.ExecuteCommand(DataPresenterCommands.ClearAllSelected);

                            xamDataGrid1.ActiveRecord = null;

                        }

                        Debug.WriteLine(xamDataGrid1.SelectedItems.Records.Count.ToString());

                    }

            • 325
              posted in reply to John Doe

              Thank you,

              The code does work, but when you select a child node, and then click next to the [+] on the left it selects its parent. Is there a way to not allow it to?