I need to be able to loop through all records in my xamlDataGrid using C# code and pull out specific values for fields and columns in each row. I also need to be able to Hide / Un-Hide a column. How can I do this?
Hello glennsep,
Thank you for your post. I have been looking through it and I suggest you look here:
http://help.infragistics.com/NetAdvantage/WPF/2011.1/CLR4.0/?page=xamDataPresenter_Iterate_through_the_Records_Collection.html
where it is described, in details, how to iterate trough the records of the XamDataGrid. As for your other question, here is a code snippet showing how to get records, fields etc. :
var myRecord = xamDataGrid1.Records[1];//get the record at index 0 var myField = xamDataGrid1.FieldLayouts[0].Fields[0];//get the field from the first fieldlayout at index 0 var myValue = (xamDataGrid1.Records[0] as DataRecord).Cells[0].Value;//get the value of the first record's first cell xamDataGrid1.FieldLayouts[0].Fields[0].Visibility = System.Windows.Visibility.Hidden;//hide the first column
Please let me now if this meets all your requirements or you need further clarifications on this matter.
Looking forward for your reply.
Stefan,
I looked at your link at this is the exact code I've been using and it is not working. Here is the code in my XAML file that creates an unbound check box:
<!-- define a style for a check box -->
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="CheckBoxCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</igDP:XamDataGrid.Resources>
Here is the code for the unbound field:
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Key="PortfolioStatus">
<igDP:UnboundField Name="DownloadBox" Label="Download">
</
igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
Here is the code that I am currently using to determine whether the unbound check box has a value or not. However whether the check box is checked or unchecked I notice the value is always null. The specific part in the code below where I check the value of the unbound checkbox is "dataRecord.Cells["DownloadBox"].Value.ToString()". What am I doing wrong?
private List<int> ReadFromCheckBoxes(RecordCollectionBase records)
{
try
// loop through all records
foreach (Record rec in records)
// this checks if the record is grouped
if (rec.RecordType == RecordType.GroupByField || rec.RecordType == RecordType.GroupByFieldLayout)
GroupByRecord groupRecord = (GroupByRecord)rec;
// we don't want to take any action here except to have the routine call itself again
if (groupRecord.HasChildren)
ReadFromCheckBoxes(groupRecord.ChildRecords);
}
// we are only interested in actual data records
else if (rec.RecordType == RecordType.DataRecord)
// reference the current data record
DataRecord dataRecord = (DataRecord)rec;
// check if this is the row that displays the portfolios
if (dataRecord.FieldLayout.Key.ToString() == "PortfolioStatus")
// determine if the check box should be displayed or not.
if (dataRecord.Cells["RequestStatus"].Value.ToString() == "Ready To Download")
if (dataRecord.Cells["DownloadBox"].Value.ToString() == "1")
lstRequests.Add(
Int32.Parse(dataRecord.Cells["RequestPortfolioServiceId"].Value.ToString()));
// check for child records (e.g. the request status row will have portfolio records as children since the grid
// is hierachial
if (dataRecord.HasChildren)
ReadFromCheckBoxes(dataRecord.ChildRecords);
// checks if record can be expanded
else if (rec.RecordType == RecordType.ExpandableFieldRecord)
ExpandableFieldRecord expandableRecord = (ExpandableFieldRecord)rec;
if (expandableRecord.HasChildren)
ReadFromCheckBoxes(expandableRecord.ChildRecords);
// return the lists of requests to download
return
lstRequests;
catch (Exception ex)
throw ex;
Thank you,
Glenn
Hello again,
I have been looking through your code snippet and I suggest you use this style for the unbound field:
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="CheckBoxCell"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <CheckBox IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Value}"></CheckBox> </ControlTemplate> </Setter.Value> </Setter> </Style>
Because the CheckBox should be bound to the cells value in order to be true or false. Please let me know if this meets all your requirements or you need any further clarifications on this matter.
Hi Stefan and Andrew,
i have 3 questions regarding xamdatagrid .
i ) i have to write generalized function to parse all xamdatagrids designed in different layouts to export it on csv file format, now i am facing problems with grids which have multiline headers or some extra bind field in view . what actually i am looking for is the property / object of xamdatagrid which create its visual layout.usually i am getting two layouts and for accessing fields i have to hard code the index of any of two.How ever , some additonal fields are rendering some times at index 0 and sometime at 1 which causing incorrect depiction of xamdatagrid in csv file.plz help to figure out the collection which is reponsible for visual rendering of grid
ii ) when i applied field chooser to my grid , it renders all properties of source object collection in its chekboxes list which are not desired to be viewed,how can i render only thos proerties in field chooser which are being rendered in xamdatagrid
iii ) field chooser reder a checkbox field for th column which doent entited with any titl/name.Actually i have palced tht column for notification image for in front of every record bt i dont want it this column to appear in field chooser
Looking forward and thank you in advance !
Hello Prasanti,
Is it possible for you to send us a small isolated sample project where your issue is reproduced, so we could be able to investigate this further for you?
Hi,
I have one XamTextEditor and one XamDataGrid.Whenever I enter the text in XamTextEditor,the text should be checked for a match with one of the fields in Xamdatagrid and only the matching records should be shown in the XamdataGrid.
Could you suggest me a way to do this.
Iam using ig:XamComboEditor for AutoComplete property.Everything is working fine except binding.ItemsSource is not getting binded to the observableCollection.I have XamComboEditor in UserControl.For binding I have used the following code
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl},path=Opportunities}"
Still its showing some numbers instead of ObservableCollection items.
One more issue here is ,once shown dropdown is not gettting collapsed when we clear the text in XamComboEditor until we press the arrow.
Please suggest me how to achieve binding and the other issue.Thanks in advance.
thanks stefan, my second query was resolved successfully, it will require some time for me to create an isolated project for the scenario as i have to create atleast 3 to 4 grids to reproduce the problem Jst i want to add here that what i require to get all those fields/columns' text which are present at xamdatagrid, that means if a field is masked with a label as caption, i want to get the label's text i will upload the sample asap
thanks stefan, my second query was resolved successfully,
it will require some time for me to create an isolated project for the scenario as i have to create atleast 3 to 4 grids to reproduce the problem
Jst i want to add here that what i require to get all those fields/columns' text which are present at xamdatagrid, that means if a field is masked with a label as caption, i want to get the label's text
i will upload the sample asap