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
{
}
}
Related
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
{
}
}
Is it possible to set the number of components in placeholder?
We can add as many as components in placeholder by using "Add to here" in gray box even the component has been already added.
I'd like to say that
In plcaceholder named 'bodyArea', you can set only one component in 'bodyArea' placeholder and you will not add any other component additionally.
Is there anyway how to do this??
There could be many ways, but this is what I used before.
// Check the number of renderings in placeholder
public static bool numberOfRenderings(string placeholderName)
{
bool rendering = true;
var renderingReferences = Sitecore.Context.Item.Visualization.GetRenderings(Sitecore.Context.Device, true);
int renderingsInPlaceholder = renderingReferences.Where(r => r.Placeholder.EndsWith('/' + placeholderName, StringComparison.OrdinalIgnoreCase)).Count();
if (renderingsInPlaceholder > 1)
{
return rendering = false;
}
return rendering;
}
In View.cshtml
if (#yourObject.numberOfRenderings("your-placeholder-key")) {
#Html.Sitecore().Placeholder("your-placeholder-key")
}
else
{
#Html.Raw("<div>Only one rendering item is available in this placeholder.</div>")
}
here is a blog where is describing how to restrict number of allowed controls :
http://www.newguid.net/sitecore/2014/restricting-the-number-of-components-in-the-sitecore-page-editor/
Other solution is using rules :
http://dotnetmafia.com/blogs/kevin/archive/2013/07/10/placeholder-settings-rules.aspx
In my program I use couple JComboBoxes with a simple list combo box model:
public class ListComboBoxModel<T> extends AbstractListModel implements ComboBoxModel {
protected List<T> list;
private T selection;
public ListComboBoxModel(List<T> list) {
this.list = list;
this.selection = getDefaultSelection();
}
protected T getDefaultSelection() {
if (list.size() > 0) {
return list.get(0);
} else {
return null;
}
}
#Override
public Object getSelectedItem() {
return selection;
}
#Override
public void setSelectedItem(Object anItem) {
selection = (T) anItem;
}
#Override
public int getSize() {
return list.size();
}
#Override
public T getElementAt(int index) {
return list.get(index);
}
}
And the problem is that when I add elements to the list that combobox is using it doesn't work as intended anymore. If I click on combo box, the list has correct length but all elements in there are empty so the list is all white. When I roll over an element it doesn't highlight. When I click anywhere in the list it always works as if I selected the recently added element. If I reduce list size back to original or even decrease it, combo box works as it should have.
To edit the lists that combo boxes use, I use JTables and the add method I implemented in their models.
public void add(T element) {
list.add(element);
fireTableDataChanged();
}
Any ideas how can I fix that?
Well if anyone were interested I solved problem by adding
fireContentsChanged(this, 0, getSize());
in a method that gets called when by table/list gets changed anywhere in the program using observer pattern.
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();
}
}
}
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();
}
}
}
}
}