.net listbox trigger event on select from javascript - c#

when I am trying to trigger an event on select from listbox asp.net user control in ie 7 8 9
$("select").trigger("change")
$("select").trigger(jQuery.Event("change", {target: $("select").get(0)}));
$("select").trigger(jQuery.Event("change", {srcElement: $("select").get(0)}));
predefined .net script fails in the predefined function that no one can change
function ValidatorOnChange(event) {
if (!event) {
event = window.event;
}
Page_InvalidControlToBeFocused = null;
var targetedControl;
if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null)) {
targetedControl = event.srcElement;
}
else {
targetedControl = event.target;
}
var vals;
if (typeof(targetedControl.Validators) != "undefined") {
vals = targetedControl.Validators;
}
else {
if (targetedControl.tagName.toLowerCase() == "label") {
targetedControl = document.getElementById(targetedControl.htmlFor);
vals = targetedControl.Validators;
}
}
var i;
for (i = 0; i < vals.length; i++) {
ValidatorValidate(vals[i], null, event);
}
ValidatorUpdateIsValid();
}
because event is suddenly null it cannot find event.target.Validators or event.srcElement.Validators. How to trigger change event properly?

You should be able to trigger with $("select").change(); and handle the event with $("select").change(function(){ //code here });

during .net generated script investigation I have over 9000 facepalm per second.
I think that if you are noob you should learn before write something. but over 9000 microsoft's indians doesn't think so
var original_trigger = $.fn.trigger;
$.fn.trigger = function(type, data) {
if($.browser.msie) {
$(this).each(function() {
window.ValidatorOnChange({
target: this
});
});
return $(this).trigger("CustomChange", data);
}
return original_trigger.apply(this, arguments);
}
this is bad too. the best way is to list change listeners, remove indian's ValidatorOnChange listener and rebind it properly. but unfortunately i have no many time to delve into this sh*t

Related

multiple filters on ICollectionView with multiple condition checks WPF

This question has been asked before in different forms, but none answer my question. I have scraped this forum and Windows dev forum for info, before posting this. I cannot make sense of how to accomplish this task.
I am at my wits end.
I have a DataGrid that is binded to an ICollectionView. This data was pulled via a stored procedure and the DataGrid is automatically generated based on the columns in each table. For reference, the SP returns a list of objects, each with a series of members like stock_symbol, stock_price, Date etc.
There are a series of filters I would like to apply to this collection view. Two comboboxes and two datepickers, to be more specific. Each with a checkbox to signify they are active.
Each checkbox event handler stores the data that was selected from the combobox or the datepicker. I am trying to compare what is in those variables, to each relevant member of the object list and send that filtered object list back to the DataGrid.
This is my code:
private void FillDataGrid()
{
//Connect contains a simple stored procedure connection to SQL server
var Client = Connect();
DTOClass[] dTOs = Client.GetData();
SetDTOClass(dTOs);
MainGrid.ItemsSource = FilterView(dTOs);
}
Here is FilterView() (apologies for the long commented sections, I am trying to include my attempts in one foul sweep):
public ICollectionView /*List<DTOClass>*/ FilterView(DTOClass[] DTO)
{
if (_CollectionViewInternal == null)
{
//Assign collected DTO object to an ICollectionView
_CollectionViewInternal =
CollectionViewSource.GetDefaultView(DTO);
}
/*
ObservableCollection<DTOClass> DTOview = null;
if (DTOViewInternal == null)
{
int j = DTO.Length;
DTOview = new ObservableCollection<DTOClass>();
for(int i = 0; i < j; i++)
{
DTOview.Add(DTO[i]);
}
DTOViewInternal = DTOview;
}
*/
//Add a default sort description to the Date column
_CollectionViewInternal.SortDescriptions.Add(new SortDescription("Date", ListSortDirection.Ascending));
//assign our view to the maingrid (move this to later in the
//MainGrid.ItemsSource = _CollectionViewInternal;
if (MainGrid.ItemsSource != null)
{
/*List<Predicate<IEnumerable<DTOClass[]>>>*/ FilteredView = new List<Predicate<IEnumerable<DTOClass[]>>>();
//DateTime _zeroDay = new DateTime(1, 1, 1);
//DateTime _now = DateTime.Now;
FilteredView.Clear();
return FilteredView = _CollectionViewInternal.Where(Function(w) w.accountname.Contains(txtFilter.Text) _
Or w.firstname.Contains(txtFilter.Text) _
Or w.lastname.Contains(txtFilter.Text) _
Or w.isenabled.Contains(txtFilter.Text) _
Or w.description.Contains(txtFilter.Text) _
Or w.lastlogontimestamp.Contains(txtFilter.Text) _
Or w.whencreated.Contains(txtFilter.Text) _
Or w.whenchanged.Contains(txtFilter.Text) _
Or w.oulocation.Contains(txtFilter.Text) _
Or w.co.Contains(txtFilter.Text) _
Or w.l.Contains(txtFilter.Text) _
Or w.state.Contains(txtFilter.Text))
//if (yearsChosen > 0)
/* Stock, Maxadj, FromDate, ToDate */
/*
if (Stock_CheckBox.IsChecked != null)
{
FilteredView.Add(new Predicate<IEnumerable<DTOClass[]>>(x => x.Where(item => item. == Stock_ComboBoxText)));
}
if (letterChosen != "Any")
{
FilteredView.Add(new Predicate<IEnumerable<DTOClass[]>>(x => x.LastName.StartsWith(letterChosen)));
}
if (genderChosen != "Any")
{
FilteredView.Add(new Predicate<IEnumerable<DTOClass[]>>(x => x.Gender.Equals(genderChosen.Substring(0, 1))));
}
_CollectionViewInternal.Filter = dynamic_Filter;
RaisePropertyChanged("PeopleView");
// Bring the current person back into view in case it moved
if (CurrentPerson != null)
{
IEnumerable<DTOClass[]> current = CurrentPerson;
_CollectionViewInternal.MoveCurrentToFirst();
_CollectionViewInternal.MoveCurrentTo(current);
}
*/
/*
if (DTOview == null)
{
DTOview = DTOViewInternal;
} else
{
DTOViewInternal.
}
*/
//var collection = DTO;
//var symbol = collection.Where(item => item.Date == ).ToList();
//DTOview = new ObservableCollection<DTOClass>();
//IEnumerable<DTOClass> DTOview2;
//List<IEnumerable<DTOClass>> FilteredView = new List<IEnumerable<DTOClass>>();
/*
if (Stock_ComboBoxText != null)
{
//var collection = DTO;
var collection = DTO.Where(item => item.stock_symbol == Stock_ComboBoxText).Cast<DTOClass>().ToList();
//DTOview.Add(filtered.Cast<DTOClass>());
//FilteredView.Add(collection.Cast<DTOClass>());
FilteredView.Add(collection);
MainGrid.ItemsSource = FilteredView[0];
//FilteredView = filtered.Cast<DTOClass>();
}
if (Maxadj_ComboBoxText != 0)
{
var collection = DTO.Where(item => item.stock_price_adj_close == Maxadj_ComboBoxText).Cast<DTOClass>().ToList();
FilteredView.Add(collection);
MainGrid.ItemsSource = FilteredView[0];
//DTOview.Add(DTO.Where(item => item.stock_price_adj_close == ).ToList());
}
if (From_DatePickValue != null)
{
var collection = DTO.Where(item => item.Date >= From_DatePickValue).Cast<DTOClass>().ToList();
FilteredView.Add(collection);
MainGrid.ItemsSource = FilteredView[0];
}
if (To_DatePickValue != null)
{
var collection = DTO.Where(item => item.Date <= To_DatePickValue).Cast<DTOClass>().ToList();
FilteredView.Add(collection);
MainGrid.ItemsSource = FilteredView[0];
}
*/
//DTOview = DTOViewInternal;
//DTOview = null;
//DTOClass[] dto = GetDTOClass();
//ListCollectionView collectionView = new ListCollectionView(DTOViewInternal);
/*
collectionView.Filter = (e) =>
{
//int j = DTO.Length;
DTOClass[] dtofiltered = e as DTOClass[];
//for (int i = 0; i < j; i++)
//{
if ((Stock_ComboBoxText != null) && (DTOview[0][i].stock_symbol == Stock_ComboBoxText))
{
return true;
}
if ((Maxadj_ComboBoxText != 0) && (DTOview[0][i].stock_price_adj_close == Maxadj_ComboBoxText))
{
return true;
}
if ((From_DatePickValue != null) && (DTOview[0][i].Date >= From_DatePickValue))
{
return true;
}
if ((To_DatePickValue != null) && (DTOview[0][i].Date <= To_DatePickValue))
{
return true;
}
}
return true;
};
*/
//return collectionView.Cast<DTOClass>().ToList();
//return collectionView.Filter;
//return null;
//MainGrid.ItemsSource = null;
//MainGrid.ItemsSource = (CollectionView)CollectionViewSource.GetDefaultView(collectionView.ToString());
}
else
{
//MainGrid.ItemsSource = DTOview[0].ToList();
//MainGrid.ItemsSource = DTOview;
//return DTOview[0].ToList();
return _CollectionViewInternal;
}
return _CollectionViewInternal;
}
I only want to filter on a column, if it's relevant checkbox is checked. This is easy pickings with one filter, but more than one is proving to be beyond challenging.
As you can see I have attempted numerous solutions. I have tried using an ObservableCollection, I have tried filtering the object list directly and then adding it to an ICollectionView. Nothing works.
I have been attempting to graft this example: Complicated Filtering ICollectionView. But I cannot make heads or tails of it. I still don't understand predicates and tbh I really can't wrap my head around how it works.
I know it's frowned upon to ask 'gimme the code' questions. But if someone could just see past that and point out what I am doing wrong here, maybe even give me the code, I would be very grateful. I have spent weeks trying to understand this and I have run out of time on this assignment.
If not, then that's cool but please refrain from commenting on this thread. Don't take pride in withholding the answer either, I am usually an embedded C programmer and I just finished a full-sized OSX-Windows port for a massive Adobe AfterFX plugin. So I don't need snide remarks or any nonsense about putting more effort into learning, I just want to finish this assignment and be done with it.
Thank you all in advance.
Code to complement above comment:
List<Predicate<IEnumerable<DTOClass[]>>> FilteredView = null;
public ICollectionView FilterView(DTOClass[] DTO)
{
List<Predicate<IEnumerable<DTOClass[]>>>FilteredView = new
List<Predicate<IEnumerable<DTOClass[]>>>();
FilteredView.Clear();
if (Stock_CheckBox.IsChecked != null)
{
FilteredView.Add(new Predicate<IEnumerable<DTOClass[]>>(x => x.Where(item => item.stock_symbol == Stock_ComboBoxText)));
}
}
I can't even get the first predicate working. Apparently .stock_symbol isn't there and I can't index item. I suppose my real question here is how do I access the stock_symbol member?
Apologies for taking so long to get there, I am extremely sleep deprived.
EDIT:
Dumb mistakes are made with no sleep.
List<Predicate<DTOClass>> FilteredView = new List<Predicate<DTOClass>>();
if (Stock_CheckBox.IsChecked != null)
{
for (int i = 0; i < DTO.Length; i++)
{
FilteredView.Add(new Predicate<DTOClass>(x => x.stock_symbol == _Stock_ComboBoxText));
//FilteredView.Add(new Predicate<DTOClass[]>>(x => x.stock_symbol == _Stock_ComboBoxText));
}
}

How to select a GuiComboBox Entry in SAP

I want to script our sap. Actually, I'm scripting the comboboxes. But I don't know, how to select a specific item.
SAPFEWSELib.dll included as refernece
public static bool SelectComboBoxItem(string ItemText)
{
int i = 0, ItInd = -1;
SAPFEWSELib.GuiComboBox GCB = GetComboBox(GFW, Criteria, Type); /*This function returns the SAPFEWSELib.GuiComboBox and works correctly*/
if (GCB != null)
{
foreach (SAPFEWSELib.GuiComboBoxEntry Entry in GCB.Entries)
{
if (Entry.Value.ToUpper().IndexOf(Item.ToUpper()) != -1)
{
/*How to select this Entry?*/
/*GCB.Entries.Item(Entry.Pos).Select() is a not contained methode*/
/*GCB.Entries.Item(Entry.Pos).Selected = true This functions for GuiTableRows and GuiGridViewRows, but not here*/
return true;
} else {
i++;
}
}
}else{
throw new System.Exception("ERROR: Unable to find combobox with current criteria!");
}
return false;
}
Does anybody has an Idea?
Ok, got it.
GCB.Value = Entry.Value;
In my testcase, the combobox was not changeable, so it never functioned.

How to stop Custom OnSaving event after first saving in SItecore?

I am trying to stop my custom OnSaving event after it has been applied to the first item in the save chain.
but so far I have not been able to, and I end up with a stackoverflow exception.
Is there a simple way of doing this ?
Best regards,
Robin
private void AddOrRemoveRedirectingItemIdFromSavingItemIdList(Item savingItem, SitecoreEventArgs sitecoreEventArgs)
{
ItemLink[] referers = Globals.LinkDatabase.GetReferrers(savingItem);
var guidList = new List<ID>();
foreach (ItemLink link in referers)
{
// checking the database name of the linked Item
if (!link.SourceDatabaseName.Equals(Context.ContentDatabase.Name, StringComparison.CurrentCultureIgnoreCase))
{
continue;
}
Item item = Context.ContentDatabase.Items[link.SourceItemID, savingItem.Language];
// adding the Item to an array if the Item is not null
if (item == null || item.Fields["301Redirect"] == null || item.Fields["301RedirectedTo"] == null)
{
continue;
}
// Update the saving item ids
CheckboxField redirectField = item.Fields["301Redirect"];
if (redirectField.Checked)
{
guidList.Add(item.ID);
}
}
if (guidList.Any())
{
this.SaveIDsToEditingItem(savingItem, guidList, false);
}
}
private void SaveIDsToEditingItem(Item editingItem, IEnumerable<ID> guidList, bool forceModified)
{
Field redirectedToFromItemId = editingItem.Fields["301RedirectedToFromItemId"];
using (new EditContext(editingItem))
{
// Saving the redirected items ids
string redirectedToFromItemIdOld = redirectedToFromItemId.Value;
string redirectedToFromItemIdNew = string.Join("\n", guidList.Select(guid => guid.ToString()));
// if the values are not changed
if (redirectedToFromItemIdNew.Equals(redirectedToFromItemIdOld))
{
return;
}
redirectedToFromItemId.Value = redirectedToFromItemIdNew;
if (forceModified)
{
editingItem.RuntimeSettings.ForceModified = true;
}
}
}
}
You can do this 2 ways. The better way would be to remove the using (new EditingContext(editingItem) section from the SaveIDsToEditingItem. In the OnItemSaving event, any changes made to the savingItem would be kept.
Alternatively, if you need to use the editing context for some reason you need to use an EventDisabler in your SaveIDsToEditingItem method:
private void SaveIDsToEditingItem(Item editingItem, IEnumerable<ID> guidList, bool forceModified)
{
Field redirectedToFromItemId = editingItem.Fields["301RedirectedToFromItemId"];
using (new EventDisabler())
{
using (new EditContext(editingItem))
{
// Saving the redirected items ids
string redirectedToFromItemIdOld = redirectedToFromItemId.Value;
string redirectedToFromItemIdNew = string.Join("\n", guidList.Select(guid => guid.ToString()));
// if the values are not changed
if (redirectedToFromItemIdNew.Equals(redirectedToFromItemIdOld))
{
return;
}
redirectedToFromItemId.Value = redirectedToFromItemIdNew;
if (forceModified)
{
editingItem.RuntimeSettings.ForceModified = true;
}
}
}
}
This will prevent the OnSaving event from being fired again.

Run code after multiple events completed

I have an event set up to fire when an item in a ListView is checked. The event calls a function which updates various controls inside my form. Among other things, I need to enable or disable buttons based on how many items are checked. This function is quite expensive.
Example:
private void listView_ItemCheck(object sender, ItemCheckEventArgs e)
{
UpdateForm();
}
Now the problem arises when a user wants to check many items at once. This causes the application to be unresponsive for a little while.
So, I would like to call UpdateForm() once after all the items were checked, instead of every time a single item is checked.
EDIT:
Here's a part of UpdateForm():
private void UpdateForm()
{
// Puts all files in the mod list in a new list
List<string> modListFiles = new List<string>(lvFiles.Items.Count);
foreach (ListViewItem lvi in lvFiles.Items)
{
modListFiles.Add(lvi.Text);
}
// Adds found files to the file list
foreach (string file in Files)
{
lvFiles.Items.Add(new ListViewItem(file));
}
// Removes files from mod list that no longer exist
List<string> deleteQue = new List<string>(lvFiles.Items.Count);
foreach (string file in modListFiles)
{
// If a file in the list doesn't exist anymore, que it to delete
if (!Files.Contains(file))
{
deleteQue.Add(file);
}
}
// Remove queued files
foreach (string file in deleteQue)
{
foreach (ListViewItem lvi in lvFiles.Items)
{
if (lvi.Text == file)
{
lvFiles.Items.Remove(lvi);
break;
}
}
}
// Grays out mod list if a profile is installed
if (InstalledProfile == null)
{
lvFiles.BackColor = SystemColors.Window;
lvFiles.ForeColor = SystemColors.WindowText;
}
else
{
lvFiles.BackColor = SystemColors.Control;
lvFiles.ForeColor = SystemColors.ControlDark;
}
// Fills out the game path if it exists
if (Directory.Exists(GamePath))
{
txtGamePath.Text = GamePath;
}
else
{
txtGamePath.Text = "Game directory does not exist!";
}
// Makes sure that the cbxProfiles_SelectedIndexChanged doesn't run UpdateForm() again
handleProfileChanged = false;
// Adds profiles to the combobox
foreach (string profile in Profiles)
{
if (!cbxProfiles.Items.Contains(profile))
{
cbxProfiles.Items.Add(profile);
}
}
// Removes nonexistant profiles from the combobox
foreach (string profile in cbxProfiles.Items)
{
if (!Profiles.Contains(profile))
{
cbxProfiles.Items.Remove(profile);
}
}
if (InstalledProfile == null)
{
btnInstallUninstall.Text = "Install";
}
else
{
btnInstallUninstall.Text = "Uninstall";
}
if (Directory.Exists(GamePath) && lvFiles.CheckedItems.Count > 0)
{
btnInstallUninstall.Enabled = true;
}
else
{
btnInstallUninstall.Enabled = false;
}
}
I've had to simplify some things so please excuse any errors I have probably made.
Some context:
I'm trying to make a program that copies files from a set directory \mods to a user specified directory GamePath. It shows all files found in \mods, then allows the user to check some of them. Clicking btnInstall will copy these files to GamePath. After this so called installing, the copied files can be removed by clicking btnInstall again.
All of the properties I made (Profiles, GamePath) get and set their values using an XML file on disk. The main ListView is called lvFiles, sometimes called mod list or file list in comments.
I've managed to speed the process of checking files up considerably by not calling UpdateForm(). Instead, I made a function UpdateButtons() that only enables/disables buttons.
This way, we do not call UpdateForm() until either the form is activated or the process exits.
Although the current code is far from perfect, all of your help was very useful and is greatly appreciated. I will probably think about the updating mechanism a bit more and apply some good threading later on.
Thank you all!
Here is the code if you want to see it:
private void UpdateButtons()
{
#region btnOpenPath
if (Directory.Exists(GamePath))
{
btnOpenPath.Enabled = true;
}
else
{
btnOpenPath.Enabled = false;
}
#endregion
#region btnInstallUninstall
if (InstalledProfile == null)
{
btnInstallUninstall.Text = "Install";
}
else
{
btnInstallUninstall.Text = "Uninstall";
}
if (Directory.Exists(GamePath) && lvFiles.CheckedItems.Count > 0)
{
btnInstallUninstall.Enabled = true;
}
else
{
btnInstallUninstall.Enabled = false;
}
#endregion
#region btnDelete, btnCheckAll, btnUncheckAll
if (InstalledProfile == null)
{
btnDelete.Enabled = true;
btnCheckAll.Enabled = true;
btnUncheckAll.Enabled = true;
}
else
{
btnDelete.Enabled = false;
btnCheckAll.Enabled = false;
btnUncheckAll.Enabled = false;
}
#endregion
}

How to handle the mouse wheel button event in ASP.NET?

I have a project which uses EXT.NET framework for the controls. I'm currently working on the behavior of closing the panel tabs such as Google Chrome and all the modern browsers does.
I couldn't find the answer to this. What is the ASCII value for the mouse scroll wheel button? How can I handle this event in C# ASP.NET?
working on Firefox, Explorer and Chrome:
$(document).ready(function() {
$(document).mousedown(function(e) {
closeTab(e);
});
});
function closeTab(e) {
if (!e) {
e = window.event;
e.which = e.keyCode;
}
if(e.which == 2){
var tbpPrincipal = <%= tbpPrincipal.ClientID %>;
var activeTab = null;
for (var i = 0; i < tbpPrincipal.items.length; i++) {
var currentTab = tbpPrincipal.items.items[i];
if (e.target.innerText == currentTab.title || e.target.textContent == currentTab.title) {
activeTab = currentTab;
break;
}
}
if (activeTab) {
var activeTabIndex = tbpPrincipal.items.findIndex('id', activeTab.id);
tbpPrincipal.remove(activeTabIndex);
}
}
return true;// to allow the browser to know that we handled it.
}

Categories