Ejemplo n.º 1
0
 public static string GetDataAt(int row, int column)
 {
     if (ws == null)
     {
         Console.WriteLine("WorkSheet nije ucitan!");
         return("ERROR");
     }
     if (row < ws.Rows.Count)
     {
         RangeRow rangeRow = ws.Rows[row];
         if (column < rangeRow.Columns.Count)
         {
             RangeColumn rangeColumn = rangeRow.Columns[column];
             if (rangeColumn != null)
             {
                 return(rangeColumn.StringValue);
             }
             else
             {
                 Console.WriteLine("Ne postoji celija!");
                 return("ERROR");
             }
         }
         else
         {
             Console.WriteLine("Ne postoji kolona!");
             return("ERROR");
         }
     }
     else
     {
         Console.WriteLine("Ne postoji red!");
         return("ERROR");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies the bound to the given grid.
        /// </summary>
        /// <param name="pColumn">The column to bound.</param>
        /// <returns>The resize delta after applying the bound.</returns>
        private double SetRangeColumnToBounds(GridViewColumn pColumn)
        {
            if (RangeColumn.IsRangeColumn(pColumn) == false)
            {
                // No need to resize.
                return(0);
            }

            double lStartWidth = pColumn.Width;

            double?lMinWidth = RangeColumn.GetRangeMinWidth(pColumn);
            double?lMaxWidth = RangeColumn.GetRangeMaxWidth(pColumn);

            if ((lMinWidth.HasValue && lMaxWidth.HasValue) && (lMinWidth > lMaxWidth))
            {
                // Invalid case. No resize.
                return(0);
            }

            // Bounding the width.
            if (lMinWidth.HasValue && pColumn.Width < lMinWidth.Value)
            {
                pColumn.Width = lMinWidth.Value;
            }
            else if (lMaxWidth.HasValue && pColumn.Width > lMaxWidth.Value)
            {
                pColumn.Width = lMaxWidth.Value;
            }

            return(pColumn.Width - lStartWidth);
        }
Ejemplo n.º 3
0
 public static string GetDataAt(int row, int column) //vadjenje informacija iz sheet-a
 {
     if (ws == null)                                 //ako ne postoji ucitan ws, daj error da nije ucitan
     {
         Console.WriteLine("WorkSheet nije ucitan!");
         return("ERROR");                                        //mora da se vrati vrednost jer nije void
     }
     if (row < ws.Rows.Count)                                    //broj izabranog reda mora da bude manji od broja redova (jer se krece od 0)
     {
         RangeRow rangeRow = ws.Rows[row];                       //dohvata se izabran red
         if (column < rangeRow.Columns.Count)                    //ako je broj izabranog reda okej, proverava se da li je kolona okej
         {
             RangeColumn rangeColumn = rangeRow.Columns[column]; //dohvata se izabrana kolona, unutar reda gadjamo sve kolone, pa uzimamo odredjenu sa indexom column
             if (rangeColumn != null)                            //ako celija u koloni nije null, znaci da postoji i vraca se tekstualna vrednost (stringvalue)
             {
                 return(rangeColumn.StringValue);
             }
             else
             {
                 Console.WriteLine("Ne postoji celija!"); //vraca se error ako celija ne postoji, ako je null
                 return("ERROR");
             }
         }
         else //ako ne postoji kolona, vraca se error
         {
             Console.WriteLine("Ne postoji kolona!");
             return("ERROR");
         }
     }
     else //ako ne postoji red, vraca se error
     {
         Console.WriteLine("Ne postoji red!");
         return("ERROR");
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Delegate called when a mouse is mouving on a thumb.
        /// </summary>
        /// <param name="pSender">The event sender.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private void OnThumbPreviewMouseMove(object pSender, MouseEventArgs pEventArgs)
        {
            Thumb lThumb = pSender as Thumb;

            if (lThumb == null)
            {
                return;
            }

            GridViewColumn lColumn = this.FindParentColumn(lThumb);

            if (lColumn == null)
            {
                return;
            }

            // Suppress column resizing for fixed and range fill columns.
            if (FixedColumn.IsFixedColumn(lColumn) || this.IsFillColumn(lColumn))
            {
                // Cursor is hidden.
                lThumb.Cursor = null;
                return;
            }

            // Check range column bounds.
            if (lThumb.IsMouseCaptured && RangeColumn.IsRangeColumn(lColumn))
            {
                double?lMinWidth = RangeColumn.GetRangeMinWidth(lColumn);
                double?lMaxWidth = RangeColumn.GetRangeMaxWidth(lColumn);

                if ((lMinWidth.HasValue && lMaxWidth.HasValue) && (lMinWidth > lMaxWidth))
                {
                    // Invalid case.
                    return;
                }

                if (this.mBackCursor == null)
                {
                    // First time = save the resize cursor.
                    this.mBackCursor = lThumb.Cursor;
                }

                // Updating the cursor.
                if (lMinWidth.HasValue && lColumn.Width <= lMinWidth.Value)
                {
                    lThumb.Cursor = Cursors.No;
                }
                else if (lMaxWidth.HasValue && lColumn.Width >= lMaxWidth.Value)
                {
                    lThumb.Cursor = Cursors.No;
                }
                else
                {
                    lThumb.Cursor = this.mBackCursor;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the flag indicating if the given is a fill column.
        /// </summary>
        /// <param name="pColumn">The column to test.</param>
        /// <returns></returns>
        private bool IsFillColumn(GridViewColumn pColumn)
        {
            if (pColumn == null)
            {
                return(false);
            }

            if (this.mListView.View == null || this.mListView.View.Columns.Count == 0)
            {
                return(false);
            }

            bool?lIsFillColumn = RangeColumn.GetRangeIsFillColumn(pColumn);

            return(lIsFillColumn.HasValue && lIsFillColumn.Value);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initialize the columns by applying there properties.
        /// </summary>
        private void InitColumns()
        {
            if (this.mListView.View == null)
            {
                return;
            }

            foreach (GridViewColumn lColumn in this.mListView.View.Columns)
            {
                if (RangeColumn.IsRangeColumn(lColumn) == false)
                {
                    continue;
                }

                double?lMinWidth = RangeColumn.GetRangeMinWidth(lColumn);
                double?lMaxWidth = RangeColumn.GetRangeMaxWidth(lColumn);
                if (lMinWidth.HasValue == false && lMaxWidth.HasValue == false)
                {
                    continue;
                }

                GridViewColumnHeader lColumnHeader = this.FindColumnHeader(this.mListView, lColumn);
                if (lColumnHeader == null)
                {
                    continue;
                }

                double lActualWidth = lColumnHeader.ActualWidth;
                if (lMinWidth.HasValue)
                {
                    lColumnHeader.MinWidth = lMinWidth.Value;
                    if (!double.IsInfinity(lActualWidth) && lActualWidth < lColumnHeader.MinWidth)
                    {
                        lColumn.Width = lColumnHeader.MinWidth;
                    }
                }

                if (lMaxWidth.HasValue)
                {
                    lColumnHeader.MaxWidth = lMaxWidth.Value;
                    if (double.IsInfinity(lActualWidth) == false && lActualWidth > lColumnHeader.MaxWidth)
                    {
                        lColumn.Width = lColumnHeader.MaxWidth;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Delegate called when a column width change.
        /// </summary>
        /// <param name="pSender">The event sender.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private void OnGridColumnWidthChanged(object pSender, EventArgs pEventArgs)
        {
            if (this.mLoaded == false)
            {
                return;
            }

            GridViewColumn lColumn = pSender as GridViewColumn;

            if (lColumn == null)
            {
                return;
            }

            // Suppress column resizing for fixed columns.
            if (FixedColumn.IsFixedColumn(lColumn))
            {
                return;
            }

            // Ensure range column within the bounds.
            if (RangeColumn.IsRangeColumn(lColumn))
            {
                // Special case: auto column width - maybe conflicts with min/max range.
                if (lColumn != null && lColumn.Width.Equals(double.NaN))
                {
                    // Resize is handled by the change header size event.
                    this.mAutoSizedColumn = lColumn;
                    return;
                }

                // ensure column bounds
                if (Math.Abs(this.SetRangeColumnToBounds(lColumn) - 0) > ZERO_WIDTH_RANGE)
                {
                    return;
                }
            }

            // Force resize.
            this.DoResizeColumns(this.mListView.View.Columns.IndexOf(lColumn));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Resizes the grid view columns.
        /// </summary>
        /// <param name="pColumnIndex">The specific index of the resized column, or -1 if the whole control is resized.</param>
        private void ResizeColumns(int pColumnIndex)
        {
            if (this.mListView.View == null || this.mListView.View.Columns.Count == 0)
            {
                return;
            }

            // Computing the listview width.
            double lActualWidth = double.PositiveInfinity;

            if (mScrollViewer != null)
            {
                lActualWidth = this.mScrollViewer.ViewportWidth;
            }
            if (double.IsInfinity(lActualWidth))
            {
                lActualWidth = this.mListView.ActualWidth;
            }
            if (double.IsInfinity(lActualWidth) || lActualWidth <= 0)
            {
                return;
            }

            // Computing column sizes.
            double lResizeableRegionCount = 0;
            double lOtherColumnsWidth     = 0;

            foreach (GridViewColumn lColumn in this.mListView.View.Columns)
            {
                if (ProportionalColumn.IsProportionalColumn(lColumn))
                {
                    double?lProportionalWidth = ProportionalColumn.GetProportionalWidth(lColumn);
                    if (lProportionalWidth != null)
                    {
                        lResizeableRegionCount += lProportionalWidth.Value;
                    }
                }
                else
                {
                    lOtherColumnsWidth += lColumn.ActualWidth;
                }
            }

            if (lResizeableRegionCount <= 0)
            {
                // No proportional columns present : commit the regulation to the scroll viewer.
                if (this.mScrollViewer != null)
                {
                    this.mScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                }

                // Searching for the first fill column.
                GridViewColumn lFillColumn = null;
                for (int lIter = 0; lIter < this.mListView.View.Columns.Count; lIter++)
                {
                    GridViewColumn lColumn = this.mListView.View.Columns[lIter];
                    if (IsFillColumn(lColumn))
                    {
                        lFillColumn = lColumn;
                        break;
                    }
                }

                if (lFillColumn != null)
                {
                    // Applying the width to the fill column taking in account the range.
                    double lOtherColumnsWithoutFillWidth = lOtherColumnsWidth - lFillColumn.ActualWidth;
                    double lFillWidth = lActualWidth - lOtherColumnsWithoutFillWidth;
                    if (lFillWidth > 0)
                    {
                        double?lMinWidth = RangeColumn.GetRangeMinWidth(lFillColumn);
                        double?lMaxWidth = RangeColumn.GetRangeMaxWidth(lFillColumn);

                        bool lSetWidth = (lMinWidth.HasValue && lFillWidth < lMinWidth.Value) == false;
                        if (lMaxWidth.HasValue && lFillWidth > lMaxWidth.Value)
                        {
                            lSetWidth = false;
                        }

                        if (lSetWidth)
                        {
                            if (this.mScrollViewer != null)
                            {
                                this.mScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                            }
                            lFillColumn.Width = lFillWidth;
                        }
                    }
                }
                return;
            }

            // Some proportional columns have been defined.
            double lResizeableColumnsWidth = lActualWidth - lOtherColumnsWidth;

            if (lResizeableColumnsWidth <= 0)
            {
                // Missing space.
                return;
            }

            // Resize proportional columns.
            double lResizeableRegionWidth = lResizeableColumnsWidth / lResizeableRegionCount;

            foreach (GridViewColumn lColumn in this.mListView.View.Columns)
            {
                if (ProportionalColumn.IsProportionalColumn(lColumn))
                {
                    if (pColumnIndex == -1)
                    {
                        // Computing the initial width.
                        double?lProportionalWidth = ProportionalColumn.GetProportionalWidth(lColumn);
                        if (lProportionalWidth != null)
                        {
                            lColumn.Width = lProportionalWidth.Value * lResizeableRegionWidth;
                        }
                    }
                    else
                    {
                        int lCurrentIndex = this.mListView.View.Columns.IndexOf(lColumn);
                        if (pColumnIndex == lCurrentIndex)
                        {
                            // Adapting the ratio so that the column can be resized.
                            ProportionalColumn.ApplyWidth(lColumn, lColumn.Width / lResizeableRegionWidth);
                        }
                        else if (lCurrentIndex > pColumnIndex)
                        {
                            // Computing the initial width for the colums after the one resized.
                            double?proportionalWidth = ProportionalColumn.GetProportionalWidth(lColumn);
                            if (proportionalWidth != null)
                            {
                                lColumn.Width = proportionalWidth.Value * lResizeableRegionWidth;
                            }
                        }
                    }
                }
            }
        }