Example #1
0
        private void btnDown_Click(object sender, EventArgs e)
        {
            if (dgvGadgets.SelectedRows.Count <= 0)
            {
                return;
            }

            Dictionary <WebGadgetItem.GadgetGridRow, int> ggs       = new Dictionary <WebGadgetItem.GadgetGridRow, int>();
            List <WebGadgetItem.GadgetGridRow>            selecteds = new List <WebGadgetItem.GadgetGridRow>();

            List <DataGridViewRow> dgvRows = new List <DataGridViewRow>();

            foreach (DataGridViewRow each in dgvGadgets.Rows)
            {
                dgvRows.Add(each);
            }
            dgvRows.Reverse();

            int fixedIndex = dgvGadgets.Rows.Count;

            foreach (DataGridViewRow grow in dgvRows)
            {
                if (!grow.Selected) //需要用這種方式取得 Selected,不然順序會亂掉。
                {
                    continue;
                }

                selecteds.Add(grow.DataBoundItem as WebGadgetItem.GadgetGridRow);

                int newIndex = grow.Index + 1;

                if (newIndex == fixedIndex)
                {
                    fixedIndex--;
                    continue;
                }

                WebGadgetItem.GadgetGridRow gg = grow.DataBoundItem as WebGadgetItem.GadgetGridRow;
                ggs.Add(gg, newIndex);
            }

            foreach (WebGadgetItem.GadgetGridRow gg in ggs.Keys)
            {
                if (ggs[gg] >= dgvGadgets.Rows.Count)
                {
                    continue;
                }

                Rows.Remove(gg);
                Rows.Insert(ggs[gg], gg);
            }

            foreach (DataGridViewRow grow in dgvGadgets.Rows)
            {
                grow.Selected = selecteds.Contains(grow.DataBoundItem as WebGadgetItem.GadgetGridRow);
            }

            dgvGadgets.Refresh();
        }
Example #2
0
 private void PlaceGadgetXmlInRow()
 {
     foreach (DataGridViewRow row in dgvGadgets.Rows)
     {
         WebGadgetItem.GadgetGridRow gg = row.DataBoundItem as WebGadgetItem.GadgetGridRow;
         XElement gxml = Record.GetGadgetXml(gg.DeployPath);
         row.Tag = gxml;
     }
 }