コード例 #1
0
ファイル: ScheduleControl.cs プロジェクト: jay3126/opencbs
 private static void FormatRow(OLVListItem item)
 {
     var installment = (Installment)item.RowObject;
     if (installment == null) return;
     if (installment.IsPending) item.BackColor = Color.Orange;
     if (installment.IsRepaid) item.BackColor = Color.FromArgb(61, 153, 57);
     if (installment.IsPending || installment.IsRepaid) item.ForeColor = Color.White;
 }
コード例 #2
0
ファイル: Adornments.cs プロジェクト: VicBoss/KR
        /// <summary>
        /// Given the item and the subitem, calculate its bounds.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="subItem"></param>
        /// <returns></returns>
        public Rectangle CalculateItemBounds(OLVListItem item, OLVListSubItem subItem) {
            if (item == null)
                return Rectangle.Empty;

            if (subItem == null)
                return item.Bounds;
            else
                return item.GetSubItemBounds(item.SubItems.IndexOf(subItem));
        }
コード例 #3
0
        private void ApplyHyperlinkStyle(int rowIndex, OLVListItem olvi)
        {
            olvi.UseItemStyleForSubItems = false;

            // If subitem 0 is given a back color, the item back color is changed too.
            // So we have to remember it here so we can used it even if subitem 0 is changed.
            Color itemBackColor = olvi.BackColor;

            for (int i = 0; i < this.Columns.Count; i++) {
                OLVListSubItem subItem = olvi.GetSubItem(i);
                if (subItem == null)
                    continue;
                OLVColumn column = this.GetColumn(i);
                subItem.BackColor = itemBackColor;
                if (column.Hyperlink && !String.IsNullOrEmpty(subItem.Url)) {
                    if (this.IsUrlVisited(subItem.Url))
                        this.ApplyCellStyle(olvi, i, this.HyperlinkStyle.Visited);
                    else
                        this.ApplyCellStyle(olvi, i, this.HyperlinkStyle.Normal);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Update the given row using the current hot item information
 /// </summary>
 /// <param name="olvi"></param>
 protected virtual void UpdateHotRow(OLVListItem olvi)
 {
     this.UpdateHotRow(this.HotRowIndex, this.HotColumnIndex, this.HotCellHitLocation, olvi);
 }
コード例 #5
0
        /// <summary>
        /// Tell the underlying list control which images to show against the subitems
        /// </summary>
        /// <param name="rowIndex">the index at which the item occurs</param>
        /// <param name="item">the item whose subitems are to be set</param>
        /// <param name="shouldClearImages">will existing images be cleared if no new image is provided?</param>
        protected virtual void SetSubItemImages(int rowIndex, OLVListItem item, bool shouldClearImages)
        {
            if (!this.ShowImagesOnSubItems || this.OwnerDraw)
                return;

            for (int i = 1; i < item.SubItems.Count; i++) {
                this.SetSubItemImage(rowIndex, i, item.GetSubItem(i), shouldClearImages);
            }
        }
コード例 #6
0
 /// <summary>
 /// Do the work required after one item in a listview have been created
 /// </summary>
 protected virtual void PostProcessOneRow(int rowIndex, int displayIndex, OLVListItem olvi)
 {
     if (this.UseAlternatingBackColors && this.View == View.Details) {
         if (displayIndex % 2 == 1) {
             olvi.BackColor = this.AlternateRowBackColorOrDefault;
         } else {
             olvi.BackColor = this.BackColor;
         }
     }
     if (this.ShowImagesOnSubItems && !this.VirtualMode) {
         this.SetSubItemImages(rowIndex, olvi);
     }
     if (this.UseHyperlinks) {
         this.ApplyHyperlinkStyle(rowIndex, olvi);
     }
     this.TriggerFormatRowEvent(rowIndex, displayIndex, olvi);
 }
コード例 #7
0
        /// <summary>
        /// Fill in the given OLVListItem with values of the given row
        /// </summary>
        /// <param name="lvi">the OLVListItem that is to be stuff with values</param>
        /// <param name="rowObject">the model object from which values will be taken</param>
        protected virtual void FillInValues(OLVListItem lvi, object rowObject)
        {
            if (this.Columns.Count == 0)
                return;

            OLVListSubItem subItem = this.MakeSubItem(rowObject, this.GetColumn(0));
            lvi.SubItems[0] = subItem;
            lvi.ImageSelector = subItem.ImageSelector;

            // Only Details and Tile views have subitems
            if (this.View == View.Details) {
                for (int i = 1; i < this.Columns.Count; i++) {
                    lvi.SubItems.Add(this.MakeSubItem(rowObject, this.GetColumn(i)));
                }
            } else {
                if (this.View == View.Tile) {
                    for (int i = 1; i < this.Columns.Count; i++) {
                        OLVColumn column = this.GetColumn(i);
                        if (column.IsTileViewColumn)
                            lvi.SubItems.Add(this.MakeSubItem(rowObject, column));
                    }
                }
            }

            // Give the item the same font/colors as the control
            lvi.Font = this.Font;
            lvi.BackColor = this.BackColor;
            lvi.ForeColor = this.ForeColor;

            // Set the check state of the row, if we are showing check boxes
            if (this.CheckBoxes) {
                CheckState? state = this.GetCheckState(lvi.RowObject);
                if (state.HasValue)
                    lvi.CheckState = (CheckState)state;
            }

            // Give the RowFormatter a chance to mess with the item
            if (this.RowFormatter != null) {
                this.RowFormatter(lvi);
            }
        }
コード例 #8
0
        /// <summary>
        /// Calculate the bounds of the edit control for the given item/column, when the listview
        /// is being owner drawn.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="subItemIndex"></param>
        /// <param name="r"></param>
        /// <returns>A rectangle that is the bounds of the cell editor</returns>
        protected Rectangle CalculateCellEditorBoundsOwnerDrawn(OLVListItem item, int subItemIndex, Rectangle r)
        {
            IRenderer renderer = null;
            if (this.View == View.Details)
                renderer = this.GetColumn(subItemIndex).Renderer ?? this.DefaultRenderer;
            else
                renderer = this.ItemRenderer;

            if (renderer == null)
                return r;
            else {
                using (Graphics g = this.CreateGraphics()) {
                    return renderer.GetEditRectangle(g, r, item, subItemIndex);
                }
            }
        }
コード例 #9
0
 /// <summary>
 /// Calculate the bounds of the edit control for the given item/column
 /// </summary>
 /// <param name="item"></param>
 /// <param name="subItemIndex"></param>
 /// <returns></returns>
 public Rectangle CalculateCellEditorBounds(OLVListItem item, int subItemIndex)
 {
     Rectangle r;
     if (this.View == View.Details)
         r = item.GetSubItemBounds(subItemIndex);
     else
         r = this.GetItemRect(item.Index, ItemBoundsPortion.Label);
     if (this.OwnerDraw)
         return CalculateCellEditorBoundsOwnerDrawn(item, subItemIndex, r);
     else
         return CalculateCellEditorBoundsStandard(item, subItemIndex, r);
 }
コード例 #10
0
 /// <summary>
 /// Return the bounds of the given cell
 /// </summary>
 /// <param name="item">The row to be edited</param>
 /// <param name="subItemIndex">The index of the cell to be edited</param>
 /// <returns>A Rectangle</returns>
 public virtual Rectangle CalculateCellBounds(OLVListItem item, int subItemIndex)
 {
     // We use ItemBoundsPortion.Label rather than ItemBoundsPortion.Item
     // since Label extends to the right edge of the cell, whereas Item gives just the
     // current text width.
     return this.CalculateCellBounds(item, subItemIndex, ItemBoundsPortion.Label);
 }
コード例 #11
0
        /// <summary>
        /// Build/rebuild all the list view items in the list
        /// </summary>
        /// <param name="shouldPreserveState">If this is true, the control will try to preserve the selection,
        /// focused item, and the scroll position (see Remarks)
        /// </param>
        /// <remarks>
        /// <para>
        /// Use this method in situations were the contents of the list is basically the same
        /// as previously.
        /// </para>
        /// <para>
        /// Due to limitations in .NET's ListView, the scroll position is only preserved if
        /// the control is in Details view AND it is not showing groups.
        /// </para>
        /// </remarks>
        public virtual void BuildList(bool shouldPreserveState)
        {
            if (this.Frozen)
                return;

            this.ApplyExtendedStyles();
            this.ClearHotItem();
            int previousTopIndex = this.TopItemIndex;
            Point currentScrollPosition = this.LowLevelScrollPosition;

            IList previousSelection = new ArrayList();
            Object previousFocus = null;
            if (shouldPreserveState && this.objects != null) {
                previousSelection = this.SelectedObjects;
                OLVListItem focusedItem = this.FocusedItem as OLVListItem;
                if (focusedItem != null)
                    previousFocus = focusedItem.RowObject;
            }

            IEnumerable objectsToDisplay = this.FilteredObjects;

            this.BeginUpdate();
            try {
                this.Items.Clear();
                this.ListViewItemSorter = null;

                if (objectsToDisplay != null) {
                    // Build a list of all our items and then display them. (Building
                    // a list and then doing one AddRange is about 10-15% faster than individual adds)
                    List<OLVListItem> itemList = new List<OLVListItem>();
                    foreach (object rowObject in objectsToDisplay) {
                        OLVListItem lvi = new OLVListItem(rowObject);
                        this.FillInValues(lvi, rowObject);
                        itemList.Add(lvi);
                    }
                    this.Items.AddRange(itemList.ToArray());
                    this.Sort();

                    if (shouldPreserveState) {
                        this.SelectedObjects = previousSelection;
                        this.FocusedItem = this.ModelToItem(previousFocus);
                    }

                    this.RefreshHotItem();
                }
            } finally {
                this.EndUpdate();
            }

            // We can only restore the scroll position after the EndUpdate() because
            // of caching that the ListView does internally during a BeginUpdate/EndUpdate pair.
            if (shouldPreserveState) {
                this.RefreshHotItem();

                // Restore the scroll position. TopItemIndex is best, but doesn't work
                // when the control is grouped.
                if (this.ShowGroups)
                    this.LowLevelScroll(currentScrollPosition.X, currentScrollPosition.Y);
                else
                    this.TopItemIndex = previousTopIndex;

            }
        }
コード例 #12
0
ファイル: Events.cs プロジェクト: heliwave/QuranCode
 /// <summary>
 /// Create an event args
 /// </summary>
 /// <param name="column"></param>
 /// <param name="control"></param>
 /// <param name="r"></param>
 /// <param name="item"></param>
 /// <param name="subItemIndex"></param>
 public CellEditEventArgs(OLVColumn column, Control control, Rectangle r, OLVListItem item, int subItemIndex) {
     this.Control = control;
     this.column = column;
     this.cellBounds = r;
     this.listViewItem = item;
     this.rowObject = item.RowObject;
     this.subItemIndex = subItemIndex;
     this.value = column.GetValue(item.RowObject);
 }
コード例 #13
0
ファイル: Events.cs プロジェクト: heliwave/QuranCode
 /// <summary>
 /// Create a new event args
 /// </summary>
 /// <param name="model"></param>
 /// <param name="item"></param>
 public TreeBranchCollapsedEventArgs(object model, OLVListItem item)
 {
     this.Model = model;
     this.Item = item;
 }
コード例 #14
0
ファイル: Events.cs プロジェクト: heliwave/QuranCode
 /// <summary>
 /// Create a new event args
 /// </summary>
 /// <param name="model"></param>
 /// <param name="item"></param>
 public TreeBranchExpandingEventArgs(object model, OLVListItem item)
 {
     this.Model = model;
     this.Item = item;
 }
コード例 #15
0
ファイル: Events.cs プロジェクト: heliwave/QuranCode
 /// <summary>
 /// Create a new event block
 /// </summary>
 /// <param name="column"></param>
 /// <param name="item"></param>
 /// <param name="subItemIndex"></param>
 /// <param name="currentValue"></param>
 /// <param name="newValue"></param>
 public SubItemCheckingEventArgs(OLVColumn column, OLVListItem item, int subItemIndex, CheckState currentValue, CheckState newValue) {
     this.column = column;
     this.listViewItem = item;
     this.subItemIndex = subItemIndex;
     this.currentValue = currentValue;
     this.newValue = newValue;
 }
コード例 #16
0
        /// <summary>
        /// Apply a style to a cell
        /// </summary>
        /// <param name="olvi"></param>
        /// <param name="columnIndex"></param>
        /// <param name="style"></param>
        protected virtual void ApplyCellStyle(OLVListItem olvi, int columnIndex, IItemStyle style)
        {
            if (style == null)
                return;

            // Don't apply formatting to subitems when not in Details view
            if (this.View != View.Details && columnIndex > 0)
                return;

            olvi.UseItemStyleForSubItems = false;

            ListViewItem.ListViewSubItem subItem = olvi.SubItems[columnIndex];
            if (style.Font != null)
                subItem.Font = style.Font;

            if (style.FontStyle != FontStyle.Regular)
                subItem.Font = new Font(subItem.Font ?? olvi.Font ?? this.Font, style.FontStyle);

            if (!style.ForeColor.IsEmpty)
                subItem.ForeColor = style.ForeColor;

            if (!style.BackColor.IsEmpty)
                subItem.BackColor = style.BackColor;
        }
コード例 #17
0
        /// <summary>
        /// Apply a style to the given row
        /// </summary>
        /// <param name="olvi"></param>
        /// <param name="style"></param>
        protected virtual void ApplyRowStyle(OLVListItem olvi, IItemStyle style)
        {
            if (style == null)
                return;

            if (this.FullRowSelect || this.View != View.Details) {
                if (style.Font != null)
                    olvi.Font = style.Font;

                if (style.FontStyle != FontStyle.Regular)
                    olvi.Font = new Font(olvi.Font ?? this.Font, style.FontStyle);

                if (!style.ForeColor.IsEmpty) {
                    if (olvi.UseItemStyleForSubItems)
                        olvi.ForeColor = style.ForeColor;
                    else {
                        foreach (ListViewItem.ListViewSubItem x in olvi.SubItems) {
                            x.ForeColor = style.ForeColor;
                        }
                    }
                }

                if (!style.BackColor.IsEmpty) {
                    if (olvi.UseItemStyleForSubItems)
                        olvi.BackColor = style.BackColor;
                    else {
                        foreach (ListViewItem.ListViewSubItem x in olvi.SubItems) {
                            x.BackColor = style.BackColor;
                        }
                    }
                }
            } else {
                olvi.UseItemStyleForSubItems = false;

                foreach (ListViewItem.ListViewSubItem x in olvi.SubItems) {
                    if (style.BackColor.IsEmpty)
                        x.BackColor = olvi.BackColor;
                    else
                        x.BackColor = style.BackColor;
                }

                this.ApplyCellStyle(olvi, 0, style);
            }
        }
コード例 #18
0
 /// <summary>
 /// Return the bounds of the given cell only until the edge of the current text
 /// </summary>
 /// <param name="item">The row to be edited</param>
 /// <param name="subItemIndex">The index of the cell to be edited</param>
 /// <returns>A Rectangle</returns>
 public virtual Rectangle CalculateCellTextBounds(OLVListItem item, int subItemIndex)
 {
     return this.CalculateCellBounds(item, subItemIndex, ItemBoundsPortion.ItemOnly);
 }
コード例 #19
0
        /// <summary>
        /// Calculate the bounds of the edit control for the given item/column, when the listview
        /// is not being owner drawn.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="subItemIndex"></param>
        /// <param name="cellBounds"></param>
        /// <returns>A rectangle that is the bounds of the cell editor</returns>
        protected Rectangle CalculateCellEditorBoundsStandard(OLVListItem item, int subItemIndex, Rectangle cellBounds)
        {
            if (this.View != View.Details)
                return cellBounds;//

            // Allow for image (if there is one)
            int offset = 0;
            object subItemImageSelector = item.ImageSelector;
            if (subItemIndex > 0)
                subItemImageSelector = ((OLVListSubItem)item.SubItems[subItemIndex]).ImageSelector;
            if (this.GetActualImageIndex(subItemImageSelector) != -1) {
                offset += this.SmallImageSize.Width + 2;
            }

            // Allow for checkbox
            if (this.CheckBoxes && this.StateImageList != null && subItemIndex == 0) {
                offset += this.StateImageList.ImageSize.Width + 2;
            }

            // Allow for indent (first column only)
            if (subItemIndex == 0 && item.IndentCount > 0) {
                offset += (this.SmallImageSize.Width * item.IndentCount);
            }

            // Do the adjustment
            if (offset > 0) {
                cellBounds.X += offset;
                cellBounds.Width -= offset;
            }

            return cellBounds;
        }
コード例 #20
0
        /// <summary>
        /// Begin an edit operation on the given cell.
        /// </summary>
        /// <remarks>This performs various sanity checks and passes off the real work to StartCellEdit().</remarks>
        /// <param name="item">The row to be edited</param>
        /// <param name="subItemIndex">The index of the cell to be edited</param>
        public virtual void EditSubItem(OLVListItem item, int subItemIndex)
        {
            if (item == null)
                return;

            if (subItemIndex < 0 && subItemIndex >= item.SubItems.Count)
                return;

            if (this.CellEditActivation == CellEditActivateMode.None)
                return;

            if (!this.GetColumn(subItemIndex).IsEditable)
                return;

            this.StartCellEdit(item, subItemIndex);
        }
コード例 #21
0
        /// <summary>
        /// Return a control that can be used to edit the value of the given cell.
        /// </summary>
        /// <param name="item">The row to be edited</param>
        /// <param name="subItemIndex">The index of the cell to be edited</param>
        /// <returns>A Control to edit the given cell</returns>
        protected virtual Control GetCellEditor(OLVListItem item, int subItemIndex)
        {
            OLVColumn column = this.GetColumn(subItemIndex);
            Object value = column.GetValue(item.RowObject) ?? this.GetFirstNonNullValue(column);

            // TODO: What do we do if value is still null here?

            // Ask the registry for an instance of the appropriate editor.
            Control editor = ObjectListView.EditorRegistry.GetEditor(item.RowObject, column, value);

            // Use a default editor if the registry can't create one for us.
            if (editor == null)
                editor = this.MakeDefaultCellEditor(column);

            return editor;
        }
コード例 #22
0
 /// <summary>
 /// Return the ListViewItem that appears immediately after the given item.
 /// If the given item is null, the first item in the list will be returned.
 /// Return null if the given item is the last item.
 /// </summary>
 /// <param name="itemToFind">The item that is before the item that is returned, or null</param>
 /// <returns>A ListViewItem</returns>
 public virtual OLVListItem GetNextItem(OLVListItem itemToFind)
 {
     if (this.ShowGroups) {
         bool isFound = (itemToFind == null);
         foreach (ListViewGroup group in this.Groups) {
             foreach (OLVListItem olvi in group.Items) {
                 if (isFound)
                     return olvi;
                 isFound = (itemToFind == olvi);
             }
         }
         return null;
     } else {
         if (this.GetItemCount() == 0)
             return null;
         if (itemToFind == null)
             return this.GetItem(0);
         if (itemToFind.Index == this.GetItemCount() - 1)
             return null;
         return this.GetItem(itemToFind.Index + 1);
     }
 }
コード例 #23
0
 /// <summary>
 /// Tell the underlying list control which images to show against the subitems
 /// </summary>
 /// <param name="rowIndex">the index at which the item occurs</param>
 /// <param name="item">the item whose subitems are to be set</param>
 protected virtual void SetSubItemImages(int rowIndex, OLVListItem item)
 {
     this.SetSubItemImages(rowIndex, item, false);
 }
コード例 #24
0
 /// <summary>
 /// Return the ListViewItem that appears immediately before the given item.
 /// If the given item is null, the last item in the list will be returned.
 /// Return null if the given item is the first item.
 /// </summary>
 /// <param name="itemToFind">The item that is before the item that is returned</param>
 /// <returns>A ListViewItem</returns>
 public virtual OLVListItem GetPreviousItem(OLVListItem itemToFind)
 {
     if (this.ShowGroups) {
         OLVListItem previousItem = null;
         foreach (ListViewGroup group in this.Groups) {
             foreach (OLVListItem lvi in group.Items) {
                 if (lvi == itemToFind)
                     return previousItem;
                 else
                     previousItem = lvi;
             }
         }
         if (itemToFind == null)
             return previousItem;
         else
             return null;
     } else {
         if (this.GetItemCount() == 0)
             return null;
         if (itemToFind == null)
             return this.GetItem(this.GetItemCount() - 1);
         if (itemToFind.Index == 0)
             return null;
         return this.GetItem(itemToFind.Index - 1);
     }
 }
コード例 #25
0
        /// <summary>
        /// Trigger FormatRow and possibly FormatCell events for the given item
        /// </summary>
        /// <param name="rowIndex"></param>
        /// <param name="displayIndex"></param>
        /// <param name="olvi"></param>
        protected virtual void TriggerFormatRowEvent(int rowIndex, int displayIndex, OLVListItem olvi)
        {
            FormatRowEventArgs args = new FormatRowEventArgs();
            args.ListView = this;
            args.RowIndex = rowIndex;
            args.DisplayIndex = displayIndex;
            args.Item = olvi;
            args.UseCellFormatEvents = this.UseCellFormatEvents;
            this.OnFormatRow(args);

            if (args.UseCellFormatEvents && this.View == View.Details) {
                // If a cell isn't given its own color, it should use the color of the item.
                // However, there is a bug in the .NET framework where the cell are given
                // the color of the ListView instead. So we have to explicitly give each
                // cell the back color that it should have.
                olvi.UseItemStyleForSubItems = false;
                Color backColor = olvi.BackColor;
                for (int i = 0; i < this.Columns.Count; i++) {
                    olvi.SubItems[i].BackColor = backColor;
                }

                // Fire one event per cell
                FormatCellEventArgs args2 = new FormatCellEventArgs();
                args2.ListView = this;
                args2.RowIndex = rowIndex;
                args2.DisplayIndex = displayIndex;
                args2.Item = olvi;
                for (int i = 0; i < this.Columns.Count; i++) {
                    args2.ColumnIndex = i;
                    args2.Column = this.GetColumn(i);
                    args2.SubItem = olvi.GetSubItem(i);
                    this.OnFormatCell(args2);
                }
            }
        }
コード例 #26
0
        /// <summary>
        /// Insert the given collection of objects before the given position
        /// </summary>
        /// <param name="index">Where to insert the objects</param>
        /// <param name="modelObjects">The objects to be inserted</param>
        /// <remarks>
        /// <para>
        /// This operation only makes sense of non-sorted, non-grouped
        /// lists, since any subsequent sort/group operation will rearrange
        /// the list.
        /// </para>
        /// <para>This method only works on ObjectListViews and FastObjectListViews.</para>
        ///</remarks>
        public virtual void InsertObjects(int index, ICollection modelObjects)
        {
            if (this.InvokeRequired) {
                this.Invoke((MethodInvoker)delegate() {
                    this.InsertObjects(index, modelObjects);
                });
                return;
            }
            if (modelObjects == null)
                return;

            this.BeginUpdate();
            try {
                // Give the world a chance to cancel or change the added objects
                ItemsAddingEventArgs args = new ItemsAddingEventArgs(modelObjects);
                this.OnItemsAdding(args);
                if (args.Canceled)
                    return;
                modelObjects = args.ObjectsToAdd;

                this.TakeOwnershipOfObjects();
                ArrayList ourObjects = ObjectListView.EnumerableToArray(this.Objects, false);

                // If we are filtering the list, there is no way to efficiently
                // insert the objects, so just put them into our collection and rebuild.
                if (this.IsFiltering) {
                    ourObjects.InsertRange(index, modelObjects);
                    this.BuildList(true);
                    return;
                }

                this.ListViewItemSorter = null;
                index = Math.Max(0, Math.Min(index, this.GetItemCount()));
                int i = index;
                foreach (object modelObject in modelObjects) {
                    if (modelObject != null) {
                        ourObjects.Insert(i, modelObject);
                        OLVListItem lvi = new OLVListItem(modelObject);
                        this.FillInValues(lvi, modelObject);
                        this.Items.Insert(i, lvi);
                        i++;
                    }
                }

                for (i = index; i < this.GetItemCount(); i++) {
                    OLVListItem lvi = this.GetItem(i);
                    this.SetSubItemImages(lvi.Index, lvi);
                }

                // Tell the world that the list has changed
                this.OnItemsChanged(new ItemsChangedEventArgs());
            } finally {
                this.EndUpdate();
            }
        }
コード例 #27
0
        /// <summary>
        /// Update the given row using the given hot item information
        /// </summary>
        /// <param name="rowIndex"></param>
        /// <param name="columnIndex"></param>
        /// <param name="hitLocation"></param>
        /// <param name="olvi"></param>
        protected virtual void UpdateHotRow(int rowIndex, int columnIndex, HitTestLocation hitLocation, OLVListItem olvi)
        {
            if (rowIndex < 0 || columnIndex < 0)
                return;

            if (this.UseHyperlinks) {
                OLVColumn column = this.GetColumn(columnIndex);
                OLVListSubItem subItem = olvi.GetSubItem(columnIndex);
                if (column.Hyperlink && hitLocation == HitTestLocation.Text && !String.IsNullOrEmpty(subItem.Url)) {
                    this.ApplyCellStyle(olvi, columnIndex, this.HyperlinkStyle.Over);
                    this.Cursor = this.HyperlinkStyle.OverCursor ?? Cursors.Default;
                } else {
                    this.Cursor = Cursors.Default;
                }
            }

            if (this.UseHotItem) {
                if (!olvi.Selected) {
                    this.ApplyRowStyle(olvi, this.HotItemStyle);
                }
            }
        }
コード例 #28
0
 /// <summary>
 /// Update the ListViewItem with the data from its associated model.
 /// </summary>
 /// <remarks>This method does not resort or regroup the view. It simply updates
 /// the displayed data of the given item</remarks>
 public virtual void RefreshItem(OLVListItem olvi)
 {
     olvi.UseItemStyleForSubItems = true;
     olvi.SubItems.Clear();
     this.FillInValues(olvi, olvi.RowObject);
     this.PostProcessOneRow(olvi.Index, this.GetItemIndexInDisplayOrder(olvi), olvi);
 }
コード例 #29
0
        private Rectangle CalculateCellBounds(OLVListItem item, int subItemIndex, ItemBoundsPortion portion)
        {
            // SubItem.Bounds works for every subitem, except the first.
            if (subItemIndex > 0)
                return item.SubItems[subItemIndex].Bounds;

            // For non detail views, we just use the requested portion
            Rectangle r = this.GetItemRect(item.Index, portion);
            if (r.Y < -10000000 || r.Y > 10000000) {
                r.Y = item.Bounds.Y;
            }
            if (this.View != View.Details)
                return r;

            // Finding the bounds of cell 0 should not be a difficult task, but it is. Problems:
            // 1) item.SubItem[0].Bounds is always the full bounds of the entire row, not just cell 0.
            // 2) if column 0 has been dragged to some other position, the bounds always has a left edge of 0.

            // We avoid both these problems by using the position of sides the column header to calculate
            // the sides of the cell
            Point sides = NativeMethods.GetScrolledColumnSides(this, 0);
            r.X = sides.X + 4;
            r.Width = sides.Y - sides.X - 5;

            return r;
        }
コード例 #30
0
        /// <summary>
        /// Really start an edit operation on a given cell. The parameters are assumed to be sane.
        /// </summary>
        /// <param name="item">The row to be edited</param>
        /// <param name="subItemIndex">The index of the cell to be edited</param>
        public virtual void StartCellEdit(OLVListItem item, int subItemIndex)
        {
            OLVColumn column = this.GetColumn(subItemIndex);
            Rectangle r = this.CalculateCellEditorBounds(item, subItemIndex);
            Control c = this.GetCellEditor(item, subItemIndex);
            c.Bounds = r;

            // Try to align the control as the column is aligned. Not all controls support this property
            Munger.PutProperty(c, "TextAlign", column.TextAlign);

            // Give the control the value from the model
            this.SetControlValue(c, column.GetValue(item.RowObject), column.GetStringValue(item.RowObject));

            // Give the outside world the chance to munge with the process
            this.cellEditEventArgs = new CellEditEventArgs(column, c, r, item, subItemIndex);
            this.OnCellEditStarting(this.cellEditEventArgs);
            if (this.cellEditEventArgs.Cancel)
                return;

            // The event handler may have completely changed the control, so we need to remember it
            this.cellEditor = this.cellEditEventArgs.Control;

            // If the control isn't the height of the cell, centre it vertically. We don't
            // need to do this when in Tile view.
            if (this.View != View.Tile && this.cellEditor.Height != r.Height)
                this.cellEditor.Top += (r.Height - this.cellEditor.Height) / 2;

            this.Invalidate();
            this.Controls.Add(this.cellEditor);
            this.ConfigureControl();
            this.PauseAnimations(true);
        }