XtraReports dual label binding - c#

I am trying to do a simple conditional statement binding in XtraReports. I have my main reports bound to my dataset, my fields (GoalAmount, GoalName, GoalNumber, GoalStart, GoalEnd).
Now GoalNumber or GoalAmount are populated. It's always one or another. So I want to do something like -
Private void Detail_BeforePrint(object sender, PrintEventArgs e) {
if ([GoalNumber] != null) {
xrLabelGoal.Text = [GoalNumber].ToString()
}
else {
xrLabelGoal.Text = [GoalAmount].ToString()
}
xrCWPerct.Text = Convert.ToString(Convert.ToInt32(xrLabelGoal.Text)/Convert.ToInt32(xrLabelCurrentValue.Text);
}
Thanks for the help.

I found the answer -
xrLabelGoal.Text = ((DataRowView)GetCurrentRow()).Row["goalnumber"].ToString();
Turns out I was missing the System.Data which allowed me to use the DataRowView. This fixed it.

Related

Binding datagridview with data from LINQ query

I'd like to apologise in advance in case my question was answered before (also the problem is probably pretty basic too). I'm pretty new to programming and there's a good chance I fail to google for answers since I don't even have a grasp of what the problem really is.
I'm trying to bind datagridview with data from linq query to entities (using Entity Framework).
I'm using this code to achieve that:
DatabaseModelContainer context = new DatabaseModelContainer();
private void FormDocumentUpdateWT_Load(object sender, EventArgs e)
{
context.Configuration.ProxyCreationEnabled = false;
context.DocumentDetailsSet.Load();
this.documentDetailsBindingSource.DataSource = (from x in context.DocumentDetailsSet.Local
where x.DocumentHeaderId == currentDocument.Id
select new
{
x.Inventory.Number,
x.Amount,
x.Containers.Name,
x.Separate,
x.Kanban
}).ToList();
dataGridViewItems.DataSource = documentDetailsBindingSource;
dataGridViewItems.Update();
dataGridViewItems.Refresh();
}
Unfortunately this is not giving me any results (datagridview doesn't show anything), eventhough the query does return data.
When I change the code like below, datagridview actually updates but (obviously) I do not get the specific properties of my desire displayed.
DatabaseModelContainer context = new DatabaseModelContainer();
private void FormDocumentUpdateWT_Load(object sender, EventArgs e)
{
context.Configuration.ProxyCreationEnabled = false;
context.DocumentDetailsSet.Load();
this.documentDetailsBindingSource.DataSource = (from x in context.DocumentDetailsSet.Local
where x.DocumentHeaderId == currentDocument.Id
select new {
x.Inventory, //this is changed
x.Amount,
x.Containers, // also changed
x.Separate,
x.Kanban
}).ToList();
dataGridViewItems.DataSource = documentDetailsBindingSource;
dataGridViewItems.Update();
dataGridViewItems.Refresh();
}
Can somebody explain to me how this works and how to work around this? Thanks in advance!

Best way to keep focus on DatePicker when validation error

I found this related question, and it seems to work (mostly) for the TextBox in a DataGridTextColumn.
How would I implement the similar behavior for a DataGridTemplateColumn that has a DatePicker in the CellEditingTemplate?
This code seems to get called endlessly, suggesting that we are trying to set the focus to the wrong element:
private void DatePickerLostFocusHandler(object sender, RoutedEventArgs routedEventArgs)
{
// What is the correct property to use here?
// datePicker.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(datePicker))
{
// Looks like this is setting focus to wrong element -- it ends up getting called repeatedly.
var element = (sender as DatePicker);
var restoreFocus = (System.Threading.ThreadStart)delegate { element.Focus(); };
Dispatcher.BeginInvoke(restoreFocus);
}
}
Thanks for any insights ---

DevExpress Set XtraTab Selected Page

I was trying to set the XtraTab Selected page in the constructor it self as follows,
public frmInquiryManagement()
{
InitializeComponent();
tabInquiryManagement.SelectedTabPage = xtraTabPage3;
}
But it doesn't work that way. Please help me to do this.
XtraTabControl does not provide this method to directly set a selected page. What i see is, to implement this method, we need to implement a loop internally.
for(int i = 0; i < xtraTabControl1.TabPages.Count; i ++)
if(xtraTabControl1.TabPages[i].Name == "someName"){
xtraTabControl1.SelectedTabPage = xtraTabControl1.TabPages[i];
break;
}
Else this is one of the clear solutions :
tabpage1.Show();
tabpage1.pageVisible=true;
xtraTabControl1.tabPages[0].selected=true;
Hope it helps.
Cheers.
If you want to achieve that you must use PageEnabled property from XtraTabPage component.
xtraTabPage3.PageEnabled = true;
private void Form1_Load(object sender, EventArgs e)
{
SelectTabByTitle("xtraTabPage3",xtraTabControl1);
}
private void SelectTabByTitle(String tabTitle, XtraTabControl tabControl)
{
if (tabControl != null)
{
XtraTabPage pageToSelect = (from curPage in tabControl.TabPages
where curPage.Text == tabTitle
select curPage).FirstOrDefault();
if (pageToSelect != null)
{
tabControl.SelectedTabPage = pageToSelect;
}
}
}
xtraTabControl1.SelectedTabPageIndex = 0;, where 0 is the index of the page you wish to display.
Your code should normally work, but it seems that the problem is that the Form has not loaded yet and the Tabs are not visible yet. Try setting the SelectedTabPage on the Load event, or the Shown event
Use the following code in the Form's Load event handler:
tabInquiryManagement.SelectedTabPage = xtraTabPage3;
tabInquiryManagement.MakePageVisible(xtraTabPage3);

LookUpEdit not selecting newly entered value when it's a double

I have 2 LookUpEdit controls from DevExpress on my form. Both use an ObservableCollection as it's datasource, one being of type string and the other of type double. The LookUpEdit control has an event called ProcessNewValue which fires when, you guessed it, a new value is entered in the control. I've added some code in this event to add the newly added value to the ObservableCollection and it automatically selects it once done. This works as expected for the string LooUpEdit but when I try it with the double LookUpEdit`, it adds it to the collection but then it clears out the control.
Here's the code to load the controls, which gets called in Form_Load():
void InitControls()
{
double[] issueNumbers = new double[5];
issueNumbers[0] = 155;
issueNumbers[1] = 156;
issueNumbers[2] = 157;
issueNumbers[3] = 158;
issueNumbers[4] = 159;
ObservableCollection<double> issues = new ObservableCollection<double>(issueNumbers);
lookupIssues.Properties.DataSource = issues;
DevExpress.XtraEditors.Controls.LookUpColumnInfoCollection colInfo = lookupIssues.Properties.Columns;
colInfo.Clear();
colInfo.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Column"));
colInfo[0].Caption = "Issue ID's";
string[] stringNumbers = Array.ConvertAll<double, string>(issueNumbers, Convert.ToString);
ObservableCollection<string> issuesString = new ObservableCollection<string>(stringNumbers);
lookupStringValue.Properties.DataSource = issuesString;
colInfo.Clear();
colInfo.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Column"));
colInfo[0].Caption = "String Issue ID's";
}
And here's the ProcessNewValue event for both (I've renamed them to try to make it easier to see which does what):
private void OnProcessNewValue_Double(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
{
ObservableCollection<double> source = (ObservableCollection<double>)(sender as LookUpEdit).Properties.DataSource;
if (source != null)
{
if ((sender as LookUpEdit).Text.Length > 0)
{
source.Add(Convert.ToDouble((sender as LookUpEdit).Text));
(sender as LookUpEdit).Refresh();
}
}
e.Handled = true;
}
private void OnProcessNewValue_String(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
{
ObservableCollection<string> source = (ObservableCollection<string>)(sender as LookUpEdit).Properties.DataSource;
if (source != null)
{
if ((sender as LookUpEdit).Text.Length > 0)
{
source.Add((sender as LookUpEdit).Text);
(sender as LookUpEdit).Refresh();
}
}
e.Handled = true;
}
As you can see, the code it identical with the exception of one converting text to a double before adding it to the collection.
Anyone know why the double value gets added to the collection but the control doesn't automatically select it like it does with a string collection? I've even tried to hard-code the newly added value right after e.Handled = true; but it still doesn't select it. What's weird is that if I run it through the debugger, I can step through and see that the lookupIssues control indeed gets the newly added value AND it's Text property is set to it, but as soon as the event terminates, the control clears it out.....really strange.
Any help is greatly appreciated!
BTW, I can add a link to a sample project that duplicates the problem but you would need to have DevExpress v12.2.6 controls installed in order to compile the project.
I posted this to the DevExpress team as well and they were gracious enough to provide the solution:
I agree that this discrepancy appears confusing as-is. The reason for the discrepancy is LookUpEdit.ProcessNewValueCore makes a call to RepositoryItemLookUpEdit.GetKeyValueByDisplayValue which returns a null value from the LookUpListDataAdapter because no implicit conversion exists from double to string. You may resolve the discrepancy with the following change to your ProcessNewValue handler:
private void OnProcessNewValue_Double(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
{
ObservableCollection<double> source = (ObservableCollection<double>)(sender as LookUpEdit).Properties.DataSource;
if (source != null) {
if ((sender as LookUpEdit).Text.Length > 0) {
double val = Convert.ToDouble((sender as LookUpEdit).Text);
source.Add(val);
e.DisplayValue = val;
(sender as LookUpEdit).Refresh();
}
}
e.Handled = true;
}
The control now behaves as expected. I hope this can help someone else out :)

Databinding in Silverlight with RIA Services

I'm trying to display the content of a table in a combobox.
I'm using the MVVM pattern and in my viewmodel class if I write this it works:
private IEnumerable<EventType> _eventTypes;
public ManageProfileModel()
{
_referenceData = new ReferenceDataContext();
_referenceData.Load(_referenceData.GetEventTypesQuery(), false);
_eventTypes = _referenceData.EventTypes;
}
Like this the combobox is displaying the data.
However, I want the _eventTypes to be a List:
private List<EventType> _eventTypes;
But if I write this:
public ManageProfileModel()
{
_referenceData = new ReferenceDataContext();
_referenceData.Load(_referenceData.GetEventTypesQuery(), false);
_eventTypes = _referenceData.EventTypes.ToList();
}
then the combobox is empty. What is wrong with that?
I want to use a List, because I want to be able to add and remove data in the list.
Best regards.
If I remember correctly, you can not convert IEnumerable to IList directly. It is little tricky. I would use of the options from the following link. I have it in bookmark since I ran into the same problem.
http://devlicio.us/blogs/derik_whittaker/archive/2008/03/28/simple-way-to-convert-ienumerable-lt-entity-gt-to-list-lt-ientity-gt.aspx
or look at this link
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/af225aa0-1cf4-40dd-ac3e-e7a19edaef00
DomainContext.Load is asynchronous, so in your second example you're creating a list that's most likely empty because the EntitySet hasn't finished loading yet. Use the code posted by StackOverflowException to defer creating the list until the EntitySet has been populated and it should work.
just a shot straight from the head...
did you try to add something like propertychanged event for your list?
so it could be that the data came async and the property was not informed about the change...
like I said ...
private List<EventType> _eventTypes;
public List<EventType> EventTypes
{
get { return _eventTypes; }
set
{
_eventTypes = value;
RaisePropertyChanged("EventTypes");
}
}
and take also a look at ObservableCollections...
Like I said just a shot...
Hope this helps
I don't have much MVVM exposure but with silverlight + RIA, I usually do something like this.
private List<EventType> _eventTypes;
public ManageProfileModel()
{
_referenceData = new ReferenceDataContext();
var op = _referenceData.Load(_referenceData.GetEventTypesQuery(), false);
op.Completed += op_Completed;
}
void po_Completed(object sender, EventArgs e)
{
var op = ( InvokeOperation<IEnumerable<EventType>>)sender;
_eventTypes = op.Value.ToList();
}

Categories