Exemplo n.º 1
0
        public InvSpider(IReadOnlyCollection <byte[]> items)
        {
            InitializeComponent();

            _items = items;

            itemGrid.ColumnCount = 4;
            itemGrid.RowCount    = items.Count;

            itemGrid.CellValueChanged += ItemGridOnCellValueChanged;
            itemGrid.CellEndEdit      += ItemGridOnCellEndEdit;

            var currentRow = 0;

            foreach (var bytes in items)
            {
                var id       = BitConverter.ToInt16(bytes, 0);
                var quantity = BitConverter.ToInt32(bytes, 8);

                itemGrid.CurrentCell       = itemGrid.Rows[currentRow].Cells[0];
                itemGrid.CurrentCell.Value = id.ToString("X");
                itemGrid.CurrentCell       = itemGrid.Rows[currentRow].Cells[1];

                var cbox = (DataGridViewComboBoxCell)itemGrid.CurrentCell;
                foreach (var item in Defs.Items)
                {
                    cbox.Items.Add(item.Name);
                }

                cbox.Items.Add("Unknown");

                var existingItem = Defs.ItemById(id);
                cbox.Value = existingItem != null ? existingItem.Name : "Unknown";

                itemGrid.Rows[currentRow].Cells[2].Value = 0;

                itemGrid.CurrentCell       = itemGrid.Rows[currentRow].Cells[2];
                itemGrid.CurrentCell.Value = quantity.ToString();
                itemGrid.CurrentCell       = itemGrid.Rows[currentRow].Cells[3];
                itemGrid.CurrentCell.Value = "Unknown";


                currentRow++;
            }
        }