public IList <Card> GetCardsFromGrid()
        {
            CardBindingSource iCardBindingSource = (CardBindingSource)this.DataSource;

            if (iCardBindingSource == null)
            {
                return(null);
            }

            //return all cards but the first one that is the column numbers.
            BindingList <ICard> bindingCards = iCardBindingSource.DataSource as BindingList <ICard>;

            if (bindingCards == null)
            {
                return(null);
            }

            List <Card> cards = new List <Card>();

            for (int i = 0; i < bindingCards.Count; i++)
            {
                cards.Add((Card)bindingCards[i]);
            }

            return(cards);
        }
        public BindingList <ICard> GetActualCardsFromGrid()
        {
            CardBindingSource   iCardBindingSource = (CardBindingSource)this.DataSource;
            BindingList <ICard> bindingCards       = iCardBindingSource.DataSource as BindingList <ICard>;

            if (bindingCards == null)
            {
                return(null);
            }

            return(bindingCards);
        }
        public void SetCardsInGrid(IList <Card> cards)
        {
            CardBindingSource   iCardBindingSource = (CardBindingSource)this.DataSource;
            BindingList <ICard> newCards           = null;

            if (cards != null)
            {
                newCards = new BindingList <ICard>();
                foreach (Card card in cards)
                {
                    newCards.Add(card);
                }
                newCards.AllowNew = true;

                //ListCardUtil.SetGroupCards(newCards, 0);
                //ListCardUtil.SetAlignment(newCards, 0);
            }

            iCardBindingSource.DataSource = newCards;
            ShowCardsInDocument();
        }
        public void MergeSelectedCards()
        {
            if (SelectedCells.Count <= 1)
            {
                return;
            }

            CardBindingSource iCardBindingSource = (CardBindingSource)this.DataSource;

            if (iCardBindingSource == null)
            {
                return;
            }

            //return all cards but the first one that is the column numbers.
            BindingList <ICard> bindingCards = iCardBindingSource.DataSource as BindingList <ICard>;

            if (bindingCards == null)
            {
                return;
            }

            if (base.SelectedCells == null)
            {
                return;
            }

            DataGridViewSelectedCellCollection selCels = base.SelectedCells;

            Card c  = null;
            Card c2 = null;

//            bindingCards.

            foreach (DataGridViewCell cell in base.SelectedCells)
            {
                //int idx = -1;
                //if (cell.OwningRow != null &&
                //    cell.OwningRow.Cells.Count > 0 &&
                //    Int32.TryParse(cell.OwningRow.Cells[0].Value.ToString(), out idx))
                //{
                //    if (idx >= 0 && idx < bindingCards.Count)
                //    {
                //        if (c == null)
                //            c = (Card)bindingCards[idx];
                //        else
                //            c2 = (Card)bindingCards[idx];
                //    }
                //}

                if (c == null)
                {
                    c = (Card)bindingCards[cell.RowIndex];
                }
                else
                {
                    c2 = (Card)bindingCards[cell.RowIndex];
                }

                if (c != null && c2 != null)
                {
                    c.merge(c2);
                    bindingCards.Remove(c2);
                    c2 = null;
                }
            }
        }