Пример #1
0
        private void rdf_OnCellUpdate(object sender, CellUpdateEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new UpdateEventHandler(this.rdf_OnCellUpdate), new object[] { sender, e });
                return;
            }

            CellUpdate(e);
        }
Пример #2
0
        /// <summary>
        /// Handles changes to an individual cell within the grid
        /// </summary>
        /// <param name="e"></param>
        private void CellUpdate(CellUpdateEventArgs e)
        {
            lock (syncRoot)
            {
                try
                {
                    // There are three options for locating the cell we wish to update.

                    // OPTION 1
                    // In this simulation, the data-feed generates a random cell based on
                    // column-index and row-index. This makes life very easy when locating
                    // the cell we need to update but it's not very realistic in a real-world
                    // application.
                    //
                    // SKACERO.ActiveRow.ActiveCell cell = this.lvBalances[e.Row, e.Column];


                    // OPTION 2
                    // In the real world it's unlikely that we'll know the cell indices;
                    // we're more likely to know the row key and the column-header key values which
                    // means that we have to actually find the cell instead of going straight
                    // to it.
                    // string keyRow = currencies[e.Row];
                    // string keyColumn = currencies[e.Column-1];
                    // SKACERO.ActiveRow.ActiveCell cell = this.lvBalances.FindCell(keyRow, keyColumn);


                    // OPTION 3
                    // If every cell is assigned a unique name then we can use it to locate
                    // the cell within the grid. In this example, the unique key was simply generated
                    // as a composite of the row name and column name but it could just as well have
                    // been an integer or a guid.
                    string keyCell = String.Format("{0}_{1}", currencies[e.Row], currencies[e.Column - 1]);
                    SKACERO.ActiveRow.ActiveCell cell = this.lvBalances.FindCell(keyCell);

                    if (cell != null)
                    {
                        // Create a new value for the cell.
                        decimal newValue = Decimal.Add(cell.DecimalValue, e.Increment);

                        // Has the value been reduced, increased, or left unchanged?
                        if (newValue < cell.DecimalValue)
                        {
                            // Reduced
                            cell.FlashBackColor         = this.cbColourful.Checked ? Color.LightGreen : Color.Yellow;
                            cell.FlashPreTextForeColor  = Color.Red;
                            cell.FlashPostTextForeColor = Color.Red;
                            cell.FlashPreText           = "▼";
                            cell.FlashPostText          = String.Empty;
                        }
                        else if (newValue > cell.DecimalValue)
                        {
                            // Increased
                            cell.FlashBackColor         = this.cbColourful.Checked ? Color.PowderBlue : Color.Yellow;
                            cell.FlashPreTextForeColor  = Color.Blue;
                            cell.FlashPostTextForeColor = Color.Blue;
                            cell.FlashPreText           = "▲";
                            cell.FlashPostText          = String.Empty;
                        }
                        else
                        {
                            // Unchanged
                            cell.FlashBackColor = Color.Yellow;
                            cell.FlashPreText   = String.Empty;
                            cell.FlashPostText  = String.Empty;
                        }

                        cell.DecimalValue = newValue;
                    }
                }
                catch (IndexOutOfRangeException exc)
                {
                    MessageBox.Show(exc.Message);
                }
            }
        }