Please see the following code on a Winform Load method:
List<CustomersDTO> res = new List<CustomersDTO>();
res = _CustomerBO.GetCustomers();
customerBindingSource.DataSource = res;
customerDataGridView.DataSource = this.customerBindingSource;
customerBindingNavigator.BindingSource = this.customerBindingSource;
Now I want to filter on Searchbutton but I am not able to see filtered record on screen.
customerBindingSource.Filter = "Active = false";
I am missing something.. I did reasearch. Can anybody give me exact code example? I read about implementing IBindingList but not sure how to do that with my BindingSource..
Can anyone help?
You don't have to implement IBindingList. You can construct a BindingList as the DataSource of your customerBindingSource. Like This:
customerBindingSource.DataSource = new BindingList<CustomersDTO>(res);
Related
Hi im new in acumatica programming i have a code that gets the row of my data then i want to get the extension of that row how do i do it here is what i got so far
InventoryItem sel = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<CROpportunityProducts.inventoryID>>>>.Select(Base, items.InventoryID);
var selex = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(sel);
how do i get that extension as you can see i tried PXCache. Get Extension but i have no luck on it. so my question is how to get the extended value of acumatica PXSELECT thanks in advance
It would help to know in which context this code is executed but the following should work.
InventoryItemExt selExt = sel.GetExtension<InventoryItemExt>();
InventoryItem sel = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<CROpportunityProducts.inventoryID>>>>.Select(Base, items.InventoryID);
if(sel != null){
InventoryItemExt selExt = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(sel);
}
I am trying to understand how to construct an AddFilterViewRequest in the Google Sheets API. However, there don't seem to be any good examples that I can locate in any programming language which demonstrate how it is used.
Specifically, I am trying to understand the FilterCriteria object, and what I need to set hiddenValues and condition to.
In my application I am trying to construct a filter that will only show the rows where the cell in the column I have selected is not empty. I can do this manually in the Google Sheets editor, and I want to replicate the same settings in my program.
This is the code as it stands...
Request request = new Request();
request.AddFilterView = new AddFilterViewRequest();
request.AddFilterView.Filter = new FilterView();
request.AddFilterView.Filter.FilterViewId = 0;
request.AddFilterView.Filter.Title = "Hide rows with errors";
request.AddFilterView.Filter.Range = new GridRange();
request.AddFilterView.Filter.Range.SheetId = 0;
request.AddFilterView.Filter.Range.StartColumnIndex = 8;
request.AddFilterView.Filter.Range.EndColumnIndex = 9;
FilterCriteria criteria = new FilterCriteria();
//criteria.Condition = BooleanCondition;
criteria.HiddenValues = new List<string>();
//criteria.HiddenValues.Add("item");
IDictionary<string, FilterCriteria> criteriaDictionary = new Dictionary<string, FilterCriteria>();
//criteriaDictionary.Add("string", criteria);
request.AddFilterView.Filter.Criteria = criteriaDictionary;
The lines that are commented out at the moment are the ones that I can seeking assistance with. I am also trying to find out what the string variable should be for the criteriaDictionary.
After posting this question I realised one way I could answer it myself would be to reverse engineer an existing spreadsheet where this filter was already applied. Based on that, I now have the following working code...
FilterCriteria criteria = new FilterCriteria();
criteria.Condition = new BooleanCondition();
criteria.Condition.Type = "NOT_BLANK";
IDictionary<string, FilterCriteria> criteriaDictionary = new Dictionary<string, FilterCriteria>();
criteriaDictionary.Add("8", criteria);
Request request = new Request();
request.AddFilterView = new AddFilterViewRequest();
request.AddFilterView.Filter = new FilterView();
request.AddFilterView.Filter.FilterViewId = 0;
request.AddFilterView.Filter.Title = "Hide rows with errors";
request.AddFilterView.Filter.Range = range1;
request.AddFilterView.Filter.Criteria = criteriaDictionary;
requests.Add(request);
I don't know why they key value was set to 8, but that's what it was in the existing spreadsheet (and that sheet only had one Filter View in it). Anyway I copied it, and it works, so I haven't found a need to change it.
I don't have a good setup right now to construct the appropriate code here (perhaps someone else can amend this or add an answer with the code inline), but in general your best bet right now for figuring out the "right way" to construct complex objects like this in the API is to create one with the UI and then do a spreadsheets.get call. You can look at the resulting object and mimic the FilterView (with your own modifications as necessary).
i could solved it just by for loops this way
for loop iterate in datasource and rest of the code as follows
ListItem test = new ListItem { Text = srText, Value = srValue}
test.Attributes.Add("data-imagesrc", "xxx");
test.Attributes.Add("data-description", "xxx");
dropListUserImages.Items.Add(test);
may be there could be error in code because i have composed the above code in notepad. i guess my above code approach will solve my problem but just wondering that can i do the same with LINQ.
here i am giving a sample code which populating dropdown by LINQ but not sure that below code will allow us to add multiple attribute value coming from db?
below sample code taken from http://stackoverflow.com/questions/14710841/making-drop-down-list-in-asp-net-by-foreach-loop
var source = Enumerable.Range(1, 1000)
.Select(i => new { Text= i.ToString(), Value=i.ToString() });
test.DataSource = source;
test.DataTextField = "Text";
test.DataValueField = "Value";
test.DataBind();
looking for guidance to achieve the same with LINQ if possible. thanks
You cannot use the DataSource + DataBind approach if you want to add custom attributes. But why don't you use a simple loop?
var source = db.TableName.Take(1000) // if you only want 1000
.Select(sr => new {
srText = sr.srText,
srValue = sr.srValue,
imagesrc = "xxx", // change
description = "xxx" // change
});
foreach(var x in source)
{
ListItem test = new ListItem { Text = x.srText, Value = x.srValue };
test.Attributes.Add("data-imagesrc", x.imagesrc);
test.Attributes.Add("data-description", x.description);
dropListUserImages.Items.Add(test);
}
I'm trying to achieve pagination of the posts i get from a RSS-feed using the System.ServiceModel.Syndication. However I cant figure out how to do this and what the best way to do it is.
As of now i use a Listview to present the data that is fetched by this in my code-behind:
// Link to the RSS-feed.
string rssUri = "feed.xml";
var doc = System.Xml.Linq.XDocument.Load(rssUri);
// Using LINQ to loop out all posts containing the information i want.
var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")
select new
{
Title = el.Element("title").Value,
PubDate = el.Element("pubDate").Value,
Enclosure = el.Element("enclosure").Attribute("url").Value,
Description = el.Element("description").Value
};
// Binding the data to my listview, so I can present the data.
lvFeed.DataSource = rssFeed;
lvFeed.DataBind();
So where do I go from here? I'm guessing one way is to work with a DataPager in my Listview? However I'm uncertain how to work with that control, should I send all of my data into some list or something like IEnumerable<>?
After some trial and error and reading up on the DataPager i came up with the following solution that is now working very well!
First off i created a class for my object, working with that i set up a select-method for my ListView initiating at page-load binding the data to it. And the trick here was to use the ICollection interface, and send the data to a list. This is the now working code for that select-method, hope it can help someone else out facing the same problem! :)
ICollection<Podcast> SampleData()
{
string rssUri = "http://test.test.com/rss";
var doc = System.Xml.Linq.XDocument.Load(rssUri);
ICollection<Podcast> p = (from el in doc.Elements("rss").Elements("channel").Elements("item")
select new Podcast
{
Title = el.Element("title").Value,
PubDate = el.Element("pubDate").Value,
Enclosure = el.Element("enclosure").Attribute("url").Value,
Description = el.Element("description").Value
}).ToList();
return p;
}
I have a winform app that fills a lot of its dropdomn fields fram a maintenance table at runtime. Each Form has a Private void FillMaintFields()
I have run into a strange error where setting the column visibility on 1 form works but on another gives me an index out of range error!
Here is the abriged method on the offending form -->
private void FillMaintFields()
{
var myMCPTableMaint = new TableMaint();
// Index 27 is Diabetic Teaching Topics
var myDataSet = myMCPTableMaint.GetMaintItem(27);
var myDataTable = myDataSet.Tables[0];
// Diabetic TeachingTopics dropdown
chkcboDiabeticTeachingTopics.Properties.DataSource = myDataTable;
chkcboDiabeticTeachingTopics.Properties.DisplayMember = "ItemDescription";
chkcboDiabeticTeachingTopics.Properties.ValueMember = "ItemID";
// Index 26 is Diabetic Teaching
myDataSet = myMCPTableMaint.GetMaintItem(26);
myDataTable = myDataSet.Tables[0];
lkuDiabeticTeaching.Properties.DataSource = myDataTable;
lkuDiabeticTeaching.Properties.PopulateColumns();
lkuDiabeticTeaching.Properties.DisplayMember = "ItemDescription";
lkuDiabeticTeaching.Properties.ValueMember = "ItemID";
lkuDiabeticTeaching.Properties.Columns[0].Visible = false;
lkuDiabeticTeaching.Properties.Columns[1].Visible = false;
lkuDiabeticTeaching.Properties.Columns[3].Visible = false;
lkuDiabeticTeaching.Properties.Columns[4].Visible = false;
}
Now here is the working function on a sister form -->
private void FillMaintFields()
{
var myMCPTableMaint = new TableMaint();
// Index 4 is Minimum Contact Schedule
var myDataSet = myMCPTableMaint.GetMaintItem(4);
var myDataTable = myDataSet.Tables[0];
lkuMinContactSchedule.Properties.DataSource = myDataTable;
lkuMinContactSchedule.Properties.PopulateColumns();
lkuMinContactSchedule.Properties.DisplayMember = "ItemDescription";
lkuMinContactSchedule.Properties.ValueMember = "ItemID";
lkuMinContactSchedule.Properties.Columns[0].Visible = false;
lkuMinContactSchedule.Properties.Columns[1].Visible = false;
lkuMinContactSchedule.Properties.Columns[3].Visible = false;
lkuMinContactSchedule.Properties.Columns[4].Visible = false;
// Index 5 is Release of Information Updated Annually
myDataSet = myMCPTableMaint.GetMaintItem(5);
myDataTable = myDataSet.Tables[0];
lkuReleaseInfoUpdateAnnually.Properties.DataSource = myDataTable;
lkuReleaseInfoUpdateAnnually.Properties.PopulateColumns();
lkuReleaseInfoUpdateAnnually.Properties.DisplayMember = "ItemDescription";
lkuReleaseInfoUpdateAnnually.Properties.ValueMember = "ItemID";
lkuReleaseInfoUpdateAnnually.Properties.Columns[0].Visible = false;
lkuReleaseInfoUpdateAnnually.Properties.Columns[1].Visible = false;
lkuReleaseInfoUpdateAnnually.Properties.Columns[3].Visible = false;
lkuReleaseInfoUpdateAnnually.Properties.Columns[4].Visible = false;}
They are all using the same method in the DAL and accessing the EXACT same table which has a structure of -->
|ItemID | CategoryID | ItemDescription | OrderID | Active|
I am at a loss here as to why it would work in 1 spot and not another. If I comment out the Columns[] portion in the offending Form it returns the correct data with NO errors but, of course ALL columns visible.
Ideas? Thanks!
EDIT 1
Based on some comments and concerns:
The error appears on the first line that tries to access the Columns[]. Wherever and whatever column that may be on the offending Form.
If I debug and look at myDataTable it shows the correct columnms and correct data.
Is the error happening on the "lkuReleaseInfoUpdateAnnually" or the "lkuMinContactSchedule"? Which control is that exactly? It seems the error is on the control side of things, seems like your control in the second form doesn't have all the columns you're expecting it to have.
EDIT: You seem to be confusing the Columns in the dataTable with the columns on your control(s). I'm not sure which control you're using, but doing:
lkuReleaseInfoUpdateAnnually.Properties.Columns[0]
does NOT mean you're indexing into the DataTable. You're indexing into the columns of your control, which may or may not be there.
Create a minimal code that still reproduces a problem. Debug that code; or, if that doesn't help, post it here. The above code doesn't really tell us anything: it's too large, too specific to your problem. We don't know how your data looks, we've got to take your word for the table structure – although C# seems to disagree.
All in all, any help anyone could offer is just fuzzy guesswork.
I have some ideas on how to better specify bugs and their origin. Something you should do, is to watch "lkuDiabeticTeaching.Properties.Columns.Count" value, if, it's less than 1 means, you do not have any columns, and probably because no population occurred.
The only thing I can see is that the first set of code is missing a call to PopulateForms() (it is included in the second set). Could that be it?
Well, I figured it out. Kinda. For some reason I need to call lkuDiabeticTeaching.Properties.ForceInitialize(); after setting the data source on the offending form.
I can only guess that because I have nested forms that somehow this was trying to fire before the control was initialized.
It now looks like this -->
// Index 26 is Diabetic Teaching
harDataSet = myHARTableMaint.GetMaintItem(26);
harDataTable = harDataSet.Tables[0];
lkuDiabeticTeaching.Properties.DataSource = harDataTable;
lkuDiabeticTeaching.Properties.ForceInitialize();
lkuDiabeticTeaching.Properties.PopulateColumns();
lkuDiabeticTeaching.Properties.DisplayMember = "ItemDescription";
lkuDiabeticTeaching.Properties.ValueMember = "ItemID";
if(lkuDiabeticTeaching.Properties.Columns.Count > 0)
{
lkuDiabeticTeaching.Properties.Columns[0].Visible = false;
lkuDiabeticTeaching.Properties.Columns[1].Visible = false;
lkuDiabeticTeaching.Properties.Columns[3].Visible = false;
lkuDiabeticTeaching.Properties.Columns[4].Visible = false;
}
Thanks to all who gave of there time.