Hi..
I have created xamdatagrid with some data.
it has 10 rows and 10 colums.
Now i want to enable cells only from column 4 to 7 for a perticular record.
I want to do like this for every record which series of cells i want to enable means it wil enable.
remaining cells should be disabled.
Can u suggest answer for this.
And one more thing.Xamfeature browser examples are helpful.
But in that c# code you are using Strings class.
What is that class..what are that properties..
If i try to use tat program individually means in xaml code u have used that Strings class properties.
How to use that Strings class in our project.??
Thank u very much.
Alex,
I gave the samples a go and ended up trying the event option. An issue of the event option is that it runs the "Loaded" every single time one expands a group hierarchy. The CVP option you show with the color value contained in one column is great for the example but I do not have that luxury. I need to calculate the value which determines what to disable and what not to disable. I don't think that is possible in pure XAML.
My first need is based on the content of one field - easy. Ok, the second one is based on date value - harder. When the "Loaded" event fires repeatedly all of the fields end up being disabled (wrong effect). Is there an event that will just run once when this thing is loaded and not every time someone clicks on it?
Here is my code behind for the event "Loaded"
Couple of notes:
1. Math.Round has not affect accept to remove the decimal place. It doesn't do any rounding - very helpful.
2. In the first loop I conditionally block the "Sr_req_ovrd" column where the "Areva" column is like "RTO". That works by itself but when I apply the second rule "Date Loop" it undoes the first.
3. None of this sticks if it only runs one? If I force it to run once and then re-open a group, all is lost. Not sure what's happening there?
Thanks,
Glenn
void c_Loaded(object sender, RoutedEventArgs e) { DataRecordCellArea drca = sender as DataRecordCellArea; DataRecord dr = drca.Record as DataRecord; string checkIt = dr.Cells["Area"].Value.ToString(); string dateRec = dr.Cells["He"].Value.ToString(); DateTime currDateTime = DateTime.Now.AddHours(1); try { // Applys to RTO-R Records Only if (checkIt.StartsWith("RTO-R")) { CellValuePresenter.FromCell(dr.Cells["Sr_req_ovrd"]).IsEnabled = false; } // Applys to all string[] splitTime = dateRec.Split('_'); StringBuilder sb = new StringBuilder(); foreach (string str in splitTime) { sb.Append(str); sb.Append(" "); } sb.Append(":00"); DateTime valDateTime = DateTime.Parse(sb.ToString()); // Handle RTO-R Records Separately if (checkIt.StartsWith("RTO-R")) { if (DateTime.Compare(valDateTime, currDateTime) < 0) { CellValuePresenter.FromCell(dr.Cells["Sr_req_ovrd"]).IsEnabled = false; CellValuePresenter.FromCell(dr.Cells["Sr_fixed_res_bias"]).IsEnabled = false; CellValuePresenter.FromCell(dr.Cells["Regulation"]).IsEnabled = false; } else if (DateTime.Compare(valDateTime, currDateTime) >= 0) { CellValuePresenter.FromCell(dr.Cells["Sr_req_ovrd"]).IsEnabled = false; } } else { if (DateTime.Compare(valDateTime, currDateTime) < 0) { CellValuePresenter.FromCell(dr.Cells["Sr_req_ovrd"]).IsEnabled = false; CellValuePresenter.FromCell(dr.Cells["Sr_fixed_res_bias"]).IsEnabled = false; CellValuePresenter.FromCell(dr.Cells["Regulation"]).IsEnabled = false; } else if (DateTime.Compare(valDateTime, currDateTime) >= 0 && !checkIt.StartsWith("RTO-R")) { CellValuePresenter.FromCell(dr.Cells["Sr_req_ovrd"]).IsEnabled = true; CellValuePresenter.FromCell(dr.Cells["Sr_fixed_res_bias"]).IsEnabled = true; CellValuePresenter.FromCell(dr.Cells["Regulation"]).IsEnabled = true; } } if (ASClientCommands.HourlyReqIsLoaded == false) { // Do for all //CellValuePresenter.FromCell(dr.Cells["Sr_req_ovrd"]).Value = Math.Round(Convert.ToDecimal(CellValuePresenter.FromCell(dr.Cells["Sr_req_ovrd"]).Value) * 100); CellValuePresenter.FromCell(dr.Cells["Sr_fixed_res_bias"]).Value = Math.Round(Convert.ToDecimal(CellValuePresenter.FromCell(dr.Cells["Sr_fixed_res_bias"]).Value) * 100); CellValuePresenter.FromCell(dr.Cells["Regulation"]).Value = Math.Round(Convert.ToDecimal(CellValuePresenter.FromCell(dr.Cells["Regulation"]).Value) * 100); } } catch (Exception ex) { Logger.LogException(LogSourceType.ClientApplication, ex); } }
Thanks for the quick response - I'll give these options a try.
Glenn,
One way to do this in xaml is with DataTrigger:
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="cvp">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Cells[department].Value}" Value="Admin">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
The other way would be using IValueConverter, like this:
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="IsEnabled">
<Setter.Value>
<Binding Converter="{StaticResource conv}" Path="Record.Cells[2].Value" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}"/>
</Setter.Value>
</Setter>
I am attaching a sample which uses both approaches - bind with DataTrigger and with converter. They are for the foreground property, but you can modify it to work for the IsEnabled property.
Let me know if you have questions on this.
No, it is not necessary I do this in code behind. If you have a way with CVP, that would be great. I have two conditions.
1. Compare one cell to the value of another and if the other cell has "somevalue" then disable cell "other"
2. Same as one but based on datetime.
Hello Glenn,
When you call ViewableChildRecords of a DataRecord you are getting the ExpandableFieldRecordPresenter and not the nested records. To get the nested records, you have to do this twice like this:
rec. ViewableChildRecords[0]. ViewableChildRecords.ToList();
The CellValuePresenter might be null if you are calling this in an event that is too early for the Presenters to be generated or when the CellValuePresenter is not in view.I can see this is fairly simple condition, which can be easily done in xaml and you will not have to iterate through all of the records. Do you have to do this in procedural code?