I'm a newbie using Infragistics. I'm trying to add context menu to a specific row/column in UltraWinGrid, which I'm not able to. Looks like adding context menu to the grid is simple but adding it to a specific row/column is not straight forward. Can you please tell me how to do this?
You could add a context menu to the form or control your grid will reside in and only display it in when they right click in the grid over the rows/cells that need that menu.
Here's an example, though it's not pretty.
private void UltraGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ContextMenu.Hide();
Point point = new System.Drawing.Point(e.X, e.Y);
UIElement uiElement = ((UltraGridBase) sender).DisplayLayout.UIElement.ElementFromPoint(point);
UltraGridCell cell = (UltraGridCell) uiElement.GetContext(typeof (UltraGridCell));
if (cell != null && UseThisContextMenu(cell))
{
ContextMenu.Show();
}
}
}
MouseDown does not work. Please use MouseUp.
private void UltraGrid1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point point = new System.Drawing.Point(e.X, e.Y);
UIElement uiElement = ((UltraGridBase)sender).DisplayLayout.UIElement.ElementFromPoint(point);
UltraGridCell cell = (UltraGridCell)uiElement.GetContext(typeof(UltraGridCell));
if (cell.Band.Index == 0)
{
if (cell.Column.Key.Equals("ColumnToShow"))
{
contextMenuStrip.Show();
}
else
{
contextMenuStrip.Hide();
}
}
}
}
}
Related
I'm trying to check if the players click on a player skull. Therefor Im using this method:
#EventHandler
public void onCLick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if(event.getView().getTitle().equals("Inventory")) {
event.setCancelled(true);
if(!(event.getCurrentItem().getItemMeta().getDisplayName() == player.getDisplayName())) {
player.sendMessage("other player");
}else{
player.sendMessage("yourself");
}
}
But if I click on my own skull, I get the other “player output” and I dont know why…
This is how I create the skull item:
private ItemStack createSkull(Player player, String... lore) {
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
SkullMeta meta = (SkullMeta) skull.getItemMeta();
meta.setDisplayName(player.getDisplayName());
meta.setOwningPlayer(player);
meta.setLore(Arrays.asList(lore));
skull.setItemMeta(meta);
return skull;
}
Not a complete answer but to optimize you code at line 6 replace: !(event.getCurrentItem().getItemMeta().getDisplayName() == player.getDisplayName()) by event.getCurrentItem().getItemMeta().getDisplayName() != player.getDisplayName()
I have the exact same problem as this guy:
How to change row color in datagridview?
The differenence is that i use WPF. So .rows doesnt exist.
Does anybody of you have a clue how to solve this?
I solved it like this:
private void dgAnzeigeKostenstelle_LoadingRow(object sender, DataGridRowEventArgs e)
{
try
{
if (Convert.ToInt32(((System.Data.DataRowView)(e.Row.DataContext)).Row.ItemArray[5]) > Convert.ToInt32(((System.Data.DataRowView)(e.Row.DataContext)).Row.ItemArray[4]))
{
e.Row.Background = new SolidColorBrush(Colors.OrangeRed);
}
}
catch
{
}
}
After entering a value in the AddNewRecord row, and clicking anywhere outside the row on the XamDataGrid seems to add the row to the collection.
How do I prevent mouse click from adding a new row to the collection.
Kindly any help
Clicking outside of the AddNewRecord ends edit mode on the record and if there were changes they are committed at that time which means the new record is added. If you were looking to only allow the record to be commmited when pressing the enter key and not by clicking another record in the grid, then you could use the following logic to set the mouse left button down as handled:
private bool editingAddNewRecord = false;
void XamDataGrid1_EditModeEnded(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndedEventArgs e)
{
this.editingAddNewRecord = false;
}
void XamDataGrid1_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e)
{
this.editingAddNewRecord = e.Cell.Record.IsAddRecord;
}
void XamDataGrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (editingAddNewRecord)
{
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordPresenter), true) as DataRecordPresenter;
if (!(drp != null && drp.IsAddRecord))
{
e.Handled = true;
}
}
}
Thanks for the answer #alhalama!
I noticed though that you don't handle the right mouse button down, and even when we do your solution doesn't work to support it. Also, with your solution I wasn't able to edit any other cells until I had hit Enter or Escape on the Add New Row record (which might be what some people want, but not me). Here is my modified solution that undoes changes to the Add New Record row's cell when the user clicks out of it, which also handles all mouse clicks (left, right, middle, etc.).
// Used to record when the user is editing a value in the Mass Edit row.
private DataRecord _addRecordCellBeingEdited = null;
private void XamDataGrid1_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e)
{
if (e.Cell.Record.IsAddRecord)
_addRecordCellBeingEdited = e.Cell.Record;
}
private void XamDataGrid1_EditModeEnded(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndedEventArgs e)
{
_addRecordCellBeingEdited = null;
}
private void XamDataGrid1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (_addRecordCellBeingEdited != null)
{
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordPresenter), true) as DataRecordPresenter;
if (!(drp != null && drp.IsAddRecord))
{
_addRecordCellBeingEdited.CancelUpdate();
}
}
}
In an inherited UltraGrid I would like know how many Bands the grid contains after I set a new value on base.DataSource. How do I find that count?
Thanks
-a-
/*****Added screendump*****/
(code is not my property so I've scrambled away some possible trade secrets)
After setting the new dataSource object to the DataSource property of the UltraGrid you could verify the count like:
ultraGrid1.DisplayLayout.Bands.Count
Hope this is what you are looking for.
Try to use PropertyChanged event of the base class UltraControlBase:
public void Form1()
{
InitializeComponents();
ultraWinGrid.PropertyChanged += new Infragistics.Win.PropertyChangedEventHandler(ultraWinGrid_PropertyChanged);
}
void ultraWinGrid_PropertyChanged(object sender, Infragistics.Win.PropertyChangedEventArgs e)
{
Infragistics.Shared.PropChangeInfo pinfo = e.ChangeInfo;
try
{
// moving through the trigger stack
while (pinfo!=null)
{
if (Equals(pinfo.PropId, Infragistics.Win.UltraWinGrid.PropertyIds.DataSource))
{
int newBandCount = this.ultraWinGrid.DisplayLayout.Bands.Count;
/// your code here
}
pinfo=pinfo.Trigger;
}
}
catch
{
}
}
I'm trying to implement a basic Javascript confirmation box on a workflow command (e.g. "are you sure you want to edit this?"). Depending on whether a users clicks yes or no, I want to move to a different state in the workflow. Here is the code I currently have (some logic is taken out):
[Serializable]
public class ConfirmAction
{
public void Process(WorkflowPipelineArgs args)
{
Item currentItem = args.DataItem;
ClientPipelineArgs clientArgs = new ClientPipelineArgs();
Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs);
}
protected void DialogProcessor(ClientPipelineArgs args)
{
if (args.IsPostBack)
{
if (args.Result != "yes")
{
args.AbortPipeline();
return;
}
}
else
{
Sitecore.Context.ClientPage.ClientResponse.Confirm("Are you sure you want to edit this?");
args.WaitForPostBack();
}
}
}
I'm new to the Pipeline model, especially in relation to Sitecore, so I'm somewhat grasping at straws. The problem that I'm having, I believe, is that I don't have a way of getting the result back to the Workflow Pipeline, from the ClientResponse pipeline, to tell it what to do.
Thank you.
EDIT:
Using Yan's information, I eventually came up with the following solution:
public void Process(WorkflowPipelineArgs args)
{
Item currentItem = args.DataItem;
ClientPipelineArgs clientArgs = new ClientPipelineArgs();
clientArgs.Parameters.Add("itemID", currentItem.ID.ToString());
clientArgs.Parameters.Add("stateID", currentItem.Fields["__Workflow state"].Value);
Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs);
}
protected void DialogProcessor(ClientPipelineArgs args)
{
if (args.IsPostBack)
{
if (args.Result != "yes")
{
Item currentItem = Sitecore.Configuration.Factory.GetDatabase("master").GetItem(args.Parameters["itemID"]);
currentItem.Editing.BeginEdit();
currentItem.Fields["__Workflow state"].Value = args.Parameters["stateID"];
currentItem.Editing.EndEdit();
return;
}
SheerResponse.Eval("window.location.reload();");
}
else
{
Sitecore.Context.ClientPage.ClientResponse.YesNoCancel("Are you sure you want to edit this?", "200", "200");
args.WaitForPostBack();
}
}
Well, I think this is where you can take advantage from ClientPipelineArgs. Let's say you add the current item ID to the parameters to pass:
public void Process(WorkflowPipelineArgs args)
{
Item currentItem = args.DataItem;
ClientPipelineArgs clientArgs = new ClientPipelineArgs();
clientArgs.Parameters.Add("id", currentItem.ID.ToString());
Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs);
}
and later on when you get positive result you get it back and move to the target workflow state (explained in comments):
protected void DialogProcessor(ClientPipelineArgs args)
{
if (args.IsPostBack)
{
if (args.Result == "yes")
{
// 1. take item ID from args.Parameters["id"];
// 2. get item by this ID
// 3. move item to target workflow state
}
}
else
{
Sitecore.Context.ClientPage.ClientResponse.Confirm("Are you sure you want to edit this?");
args.WaitForPostBack();
}
}
This might require some minor changes (I didn't run it myself before posting), but hope you get the idea.