Im currently trying to fix some bugs in a system using C# in VS 2008.
The problem goes as follows:
The client wants some controls to be sorted. The form consists of four controls. Two of which are binded with BindingSourceA lets say and the other two with BindingSourceB.
One of the controls binded with BindingSourceA displays a code and the other one a name. Same goes for BindingSourceB.
Control1 needs to be sorted using the Code display member/column while Control2 needs to be sorted using the Name display member/column. Same goes for controls 3 and 4.
After some poking around i found that BindingSourceA.Sort = "Code ASC and BindingSourceB.Sort = "Code ASC do the job.
BUT i need something along the lines of BindingSourceA.Sort = "Code ASC, Name ASC" which also was the result of my poking around. The problem is that it doesnt do the trick for me.. Its either one or the other. I even tried BindingSourceA.Sort = "Code ASC"; BindingSourceA.Sort = "Name ASC"; but that didnt work either..
Let me know if you need anymore info.
Thanks in advance
The sorting support of data-bindings actually depends entirely on the underlying data implementation, and whether it supports IBindingList.SupportsSorting, IBindingListView.SupportsAdvancedSorting, neither, or both. Personally: just sort the data separately (via LINQ, perhaps), and then data-bind it. Avoids the entire issue and works for any data source.
Related
Hi :) What I'm trying to achieve is creating a Contact selector that, when you click on the selector icon, it brings up a filtered result of the contacts table that only shows Contacts related to that specific company, as shown below:
The above image is in the Sales Orders screen, and I'm aiming to actually have it in the Projects screen. So when I tried moving it over, making sure to have the same setup, it doesn't seem to be working in the Projects screen.
When I try opening the selector, the box is empty. I thought that maybe the problem was that the values I was trying to match between the PMProject table and the BAccount table weren't matching, so I used the Description field to output the values I was getting, and they appear to be the same.
This is the setup I am using to create the selector:
[PXUIField(DisplayName="Contact")]
[PXSelector(typeof(Search2<Contact.displayName,
LeftJoin<BAccount, On<BAccount.bAccountID, Equal<Contact.bAccountID>>>,
Where<Contact.contactType, Equal<ContactTypesAttribute.person>>>))]
[PXRestrictor(typeof(
Where<Current<PMContact.customerID>,
Like<BAccount.bAccountID>>), "")]
It's exactly the same setup that I was using for the Sales Order screen, just obviously now it's using the CustomerID of PMProject instead.
Is there something I am doing incorrectly? Any help would be appreciated :D
UPDATE
Thanks for the answer Joseph! The contact field still shows up as being empty when I click into it. See below:
This is how I added the solution:
It seems that your join with the BAccount might not be required.
Also, where are you using the displayname in "Search2<Contact.displayName"?
Did you try something like this:
[PXSelector(typeof(Search<Contact.contactID, Where<Contact.contactType, Equal<ContactTypesAttribute.person>,
And<Where<Contact.contactID, Equal<Current<PMContact.customerID>>>>>>))]
I managed to solve this issue. Joseph's answer made me rethink how I was matching contacts with the current project, as instead of using the BAccount table, I could use the Contact table instead.
I found that I just needed to compare the Contact.bAccountID field with the value of the PMContact.customerID field, and that would give me all the associated contacts.
Adding this comparison to the PXRestrictor solved this issue for me :)
[PXDBString(50)]
[PXUIField(DisplayName="Contact")]
[PXSelector(typeof(Search2<Contact.displayName,
LeftJoin<BAccount, On<BAccount.bAccountID, Equal<Contact.bAccountID>>>,
Where<Contact.contactType, Equal<ContactTypesAttribute.person>>>))]
[PXRestrictor(typeof(
Where<Current<PMContact.customerID>,
Like<Contact.bAccountID>>), "")]
It's a struggle with any application that provides select fields, that are populated by a certain datasource: Everything works fine in the first place, but once the application ages, some older entries might be deleted, leading to the problem that prior select fields can no longer access the entity in question.
Opening a view, where a select points to an already deleted datarow will (best case) show empty string.
We designed our system in a way, that deletions are not real delete-operations, but only the setting of a deleted flag. (So, all the information is still there)
However, when using Databindings along with C# (or even if not) the most blatant use case is still not covered by general mechanics (I assume):
Select-Field should show all NOT-Deleted-Entities while creating a new object containing references to the entity in question.
Select-Field (populated the very same way) should show the "deleted" entity, if it was selected "days/months/years" ago.
Is there a "handy" solution to this?
Currently we are using a "Proxy-Method" for every datasource, which will reload the data of the deleted entity, if it's not in the "available data" collection - but it's hard to believe there is no better way to deal with this, as this problem applies for almost every language out there?
In a normalized database you would have a constraint with ON DELETE NO ACTION/RESTRICT event that would prevent removal of a referenced element from the list. It would force you to decide what is to be done with the referencing rows.
With your manually-controlled deletions this could have been covered by a trigger. As none of these were implemented, you are left with only one thing to do: updating the dropdown with the selected option before rendering the UI. My approach (in Java, I'm not good at C#):
List<String> options = getNonDeletedWhatever();
if (!options.contains(currentEntity.getWhatever())) {
options.add(currentEntity.getWhatever()); // This optionally inserts an outdated value
}
or simply:
Set<String> options = getNonDeletedWhatever();
options.add(currentEntity.getWhatever()); // This optionally inserts an outdated value
I solve it by creating a list of available (non-deleted) items and if the selected item is a deleted one, then I add that item to the list.
This list becomes the data source for my dropdown.
I'm experimenting with C#/.net/WPF all for the first time. I've created a project and set up a datasource (just a table with some sample data) and created two tableadapters named Prods and Prods1 - the latter has a filter applied in the query to return slightly different results. I've dropped both tables on my form and both dutifully display their respective data.
I thought I would then swap the data source for each. So the default generated Window_Loaded:
MSDSTest.prodtestDataSet prodtestDataSet = ((MSDSTest.prodtestDataSet)(this.FindResource("prodtestDataSet")));
// Load data into the table Prods. You can modify this code as needed.
MSDSTest.prodtestDataSetTableAdapters.ProdsTableAdapter prodtestDataSetProdsTableAdapter = new MSDSTest.prodtestDataSetTableAdapters.ProdsTableAdapter();
prodtestDataSetProdsTableAdapter.Fill(prodtestDataSet.Prods);
System.Windows.Data.CollectionViewSource prodsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("prodsViewSource")));
prodsViewSource.View.MoveCurrentToFirst();
// Load data into the table Prods1. You can modify this code as needed.
MSDSTest.prodtestDataSetTableAdapters.Prods1TableAdapter prodtestDataSetProds1TableAdapter = new MSDSTest.prodtestDataSetTableAdapters.Prods1TableAdapter();
prodtestDataSetProds1TableAdapter.Fill(prodtestDataSet.Prods1);
System.Windows.Data.CollectionViewSource prods1ViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("prods1ViewSource")));
prods1ViewSource.View.MoveCurrentToFirst();
I now want to make the first data grid (prodsViewSource) instead display the data for the second table, and ignore the second table entirely. So, I changed that as follows:
MSDSTest.prodtestDataSet prodtestDataSet = ((MSDSTest.prodtestDataSet)(this.FindResource("prodtestDataSet")));
// Load data into the table Prods. You can modify this code as needed.
MSDSTest.prodtestDataSetTableAdapters.Prods1TableAdapter prodtestDataSetProdsTableAdapter = new MSDSTest.prodtestDataSetTableAdapters.Prods1TableAdapter();
prodtestDataSetProdsTableAdapter.Fill(prodtestDataSet.Prods1);
System.Windows.Data.CollectionViewSource prodsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("prodsViewSource")));
prodsViewSource.View.MoveCurrentToFirst();
With the second block having been commented out.
I must be missing something fundamental - what I think I'm doing is redefining the prodtestDataSetProdsTableAddapter variable to use an instance of the prods1 table adapter, and then using that to populate the prodsViewSource grid on the form, but I end up with a blank. Where's my error?
...
Well, I posted this after beating my head against it for an hour and, minutes later, realized the FAR easier thing to do is to just change the datacontext property of the grid in question.
I would still like to understand why doing it the vastly more complicated-bordering-on-Rube-Goldbergian way didn't work, though, so if anyone can explain that, it would still be welcome.
I am utilizing Devexpress Gridview and I am having a caching problem.
I have developed a page like here: http://mvc.devexpress.com/GridView/SimpleCustomBinding
It is working as it is supposed to be. However, if I update a column value in the database (Mssql), Gridview does not change the value.
Searched the web and found EnableRowsCache must be false but I could not implemented it since I think this property is available for different kind (or version) of Gridview and We have been using MVC extensions.
Does anybody know how to disable cache and make it show the "fresh" data?
------ UPDATE ------
After a lot of digging and searching, it is clear now that the caching is not due to devexpress, but it is the result of linq to sql. It is a property of linq that it caches the results of view and does not show the updated value.
This issue was a major headheache to us and now I have come up with a conclusion with my colleague.
PROBLEM
First of all, suppose that you have a view in your db, name: ViewBook
ViewBook
Id | Title | Author
And you write the following query:
(from VB in Connection.ViewBook
select VB).ToList();
As a result you will get a list of rows.
Then, if you update a row in your db, this query will not show the fresh data, still returns the old data.
SOLUTION
In order to solve this, first define an object:
public class ViewBookObject : ViewBook
{
//this object will have all the properties of ViewBook.
}
then in the query:
(from VB in Connection.ViewBook
select new ViewBookObject {
Id = VB.Id,
Title = VB.Title,
Author = VB.Author
}).ToList();
This query will always show the fresh data.
CONCLUSION
I have written this solution to here for people who have similar problem to this situation.
I hope this helps everyone.
I have a relatively complex dataset (numerous tables, some with multiple records) generated from reading in an XML file. I need to connect said dataset fields to an ASP form. At the moment I'm assigning them manually, like so in the pageload:
txt_first_init.Text = formData.ds.Tables["phrmHdrKey"].Rows[0]["first_init"].ToString();
txt_last_name.Text = formData.ds.Tables["phrmHdrKey"].Rows[0]["last_name"].ToString();
ddl_pregnancy_flag.SelectedValue = formData.ds.Tables["pPhrm"].Rows[0]["pregnancy_flag"].ToString();
And conversely when it's time to submit.
formData.ds.Tables["phrmHdrKey"].Rows[0]["first_init"] = txt_first_init.Text;
formData.ds.Tables["phrmHdrKey"].Rows[0]["last_name"] = txt_last_name.Text;
formData.ds.Tables["pPhrm"].Rows[0]["pregnancy_flag"] = ddl_pregnancy_flag.SelectedValue.ToString();
I did some looking into binding the textboxes (and dropdownlists, and checkboxes, and and and...) directly, but it seemed to be too many formats to use.
So this works fine, but as the number of fields increases, those load and unload lists are going to get unwieldy.
Trying to come up with a way to make a future update or addition so said list neater. I've gotten a very hand-wavy suggestion to place the two columns of names into a list, but unsure how to set such up, and how to load the items into a function that could evaluate and run the resulting commands.
Thoughts?
see here: Dynamic Form Generation in ASP.NET
looks like MS Dynamic Data is the answer.