Hello,
i have a Xamdatagrid with a field Checkbox on the Label ,then i would like to enter in the values of all records that i checked (see photo below ) ....
with this is a code (i am using for Button) i can get the 3 Records but from the First Row,Second Row and Third Row instead i would like to get the records checked..
for (int i = 0; i < xamDataGrid1.SelectedItems.Records.Count; i++) { string first = (xamDataGrid1.Records[i] as DataRecord).Cells[0].Value.ToString(); string second = (xamDataGrid1.Records[i] as DataRecord).Cells[1].Value.ToString(); }
Hello An,
From the screenshot that you have provided, I cannot quite tell exactly how you are placing the Checkbox in your XamDataGrid Field, but I imagine you are likely using a TemplateField or a CellValuePresenter style modification or something of the like.
Either way, I would expect that the Checkbox that you are placing in your Field is tied back to a property on your underlying data item using a binding, likely to the IsChecked property of those Checkboxes. As such, in order to get the checked rows, I would recommend first querying your data to get the underlying data items that have a value of "true" for this bound property. In doing so, you can then use the XamDataGrid.GetRecordsFromDataItems method to get the actual record objects. You can read further about this method here.
Please let me know if you have any other questions or concerns on this matter.
dear Andrew,
thanks for your response ...
here is the code how is place the CheckBox in the XamDataGrid
<Style TargetType="{x:Type igDP:RecordSelector}"> <Style.Triggers> <DataTrigger Binding="{Binding RecordType}" Value="FilterRecord"> <Setter Property="Template" > <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:RecordSelector}"> <Button Name="ClearButton" VerticalAlignment="Center" HorizontalAlignment="Center" Style="{DynamicResource {x:Static igDP:DataPresenterBase.FilterRecordClearButtonStyleKey}}" Visibility="{TemplateBinding FilterClearButtonVisibility}"/> <ControlTemplate.Triggers> <Trigger Property="FilterClearButtonVisibility" Value="Visible"> <Setter Property="Command" TargetName="ClearButton" Value="{x:Static igDP:DataPresenterCommands.ClearActiveRecordCellFilters}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:RecordSelector}"> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Loaded="CheckBox_Loaded_1" Checked="Child_CheckBox_Checked" Unchecked="Child_CheckBox_Unchecked" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Record.IsSelected, Mode=TwoWay}"/> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type igDP:HeaderPrefixArea}" BasedOn="{x:Null}"> <Setter Property="Visibility" Value="Visible" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:HeaderPrefixArea}"> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Loaded="CheckBox_Loaded" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/> </ControlTemplate> </Setter.Value> </Setter> </Style>
truly i can get the number of the record selected but i cannot get the data of each record selected.
Hope this helps to make understand.
Thanks
I can see that you have bound your Checkbox to the IsSelected property of the records, and as such, I would recommend that you use the XamDataGrid.SelectedItems.Records collection to get the record that are checked in this case, as this will return all of the selected DataRecords.
As for actually getting the data of each record selected, I would recommend that you utilize the DataItem property of each DataRecord. In doing so, you can obtain each underlying data item to the records that you have selected.