Пример #1
0
 /// <summary>
 /// Controls the way the datagridview handles row selections
 /// </summary>
 /// <param name="sender">Not used</param>
 /// <param name="e">Mouse event args</param>
 private void ExceptionRules_MouseDown(object sender, MouseEventArgs e)
 {
     DataGridView.HitTestInfo hti;
     hti = exceptionRulesDGV.HitTest(e.X, e.Y);
     if (e.Button == MouseButtons.Right)
     {
         if (hti.Type == DataGridViewHitTestType.Cell)
         {
             if (!((DataGridViewRow)(exceptionRulesDGV.Rows[hti.RowIndex])).Selected)
             {
                 exceptionRulesDGV.ClearSelection();
                 ((DataGridViewRow)exceptionRulesDGV.Rows[hti.RowIndex]).Selected = true;
             }
             separatorM.Visible   = true;
             removeEntryM.Visible = true;
         }
         else
         {
             separatorM.Visible   = false;
             removeEntryM.Visible = false;
             this.exceptionRulesDGV.ClearSelection();
         }
     }
     if (e.Button == MouseButtons.Left)
     {
         if (hti.Type != DataGridViewHitTestType.Cell)
         {
             this.exceptionRulesDGV.ClearSelection();
         }
     }
 }
Пример #2
0
        public void searchFunction(DataGridView dg1,TextBox txt)
        {
            dg1.ClearSelection();
            try
            {

                dg1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                foreach (DataGridViewRow row in dg1.Rows)
                {

                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        if (cell.Value.ToString().Equals(txt.Text.Trim().ToString()) && txt.Text != "")
                        {
                            row.Selected = true;
                        }

                    }
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.ToString());
            }
        }
Пример #3
0
        public static void IniDropDownList(DataGridView dgw, string dbtype, string filetype)
        {
            dgw.AutoGenerateColumns = false;
            dgw.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgw.Columns[dgw.ColumnCount - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            MySqlDataContext db = MySqlHelper.DataContext;
            var res = from tmp in db.CfGTemplate
                      select tmp;
            if (dbtype != "")
            {
                res = res.Where(x => x.DbType == dbtype);
            }
            if (filetype != "")
            {
                res = res.Where(x => x.FileType.Contains(filetype));
            }
            List<tmpinfo> ztlist = (from tmp in res
                                    select new tmpinfo() { Id = tmp.ID, Name = tmp.Name, Dbtype = tmp.DbType, Filetype = tmp.FileType, Path = tmp.Path }).ToList<tmpinfo>();
            if (filetype.IndexOf("xls") >= 0)
            {
                ztlist.Insert(0, new tmpinfo() { Id = 0, Name = "新建模板", Dbtype = dbtype, Filetype = "xls|xlsx", Path = "" });
            }
            dgw.DataSource = ztlist;
            dgw.Parent.Height = dgw.Rows.Count * dgw.RowTemplate.Height + dgw.ColumnHeadersHeight + 8;
            dgw.ClearSelection();

        }
Пример #4
0
 public void Grid(ref DataGridView grid, DataTable dt, bool codigoVisible, bool clearSelection, bool autoSizeColumnMode)
 {
     try
     {
         grid.AutoGenerateColumns = false;
         grid.MultiSelect = false;
         grid.ReadOnly = true;
         grid.Columns[1].Visible = codigoVisible;
         grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
         grid.DataSource = dt;
         if (autoSizeColumnMode)
         {
             int i;
             for (i = 0; i <= grid.ColumnCount - 1; i++)
             {
                 grid.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
             }
         }
         if (clearSelection)
         {
             grid.ClearSelection();
         }
     }
     catch
     {
     }
 }
Пример #5
0
 private void initialiseTable()
 {
     if (this.table != null) this.Controls.Remove(this.table);
     table = new DataGridView();
     table.Dock = DockStyle.Fill;
     table.Size = new Size(this.Size.Width, this.Size.Height);
     table.RowHeadersVisible = false;
     table.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
     table.MultiSelect = false;
     table.AllowUserToAddRows = false;
     table.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
     String stm = "SELECT name, code, credits FROM Modules WHERE year = @year";
     SQLiteDataAdapter adapt = new SQLiteDataAdapter(stm, DBSchema.connection());
     adapt.SelectCommand.Parameters.Add(new SQLiteParameter("@year", year));
     DataSet ds = new DataSet();
     adapt.Fill(ds, "Modules");
     table.DataSource = ds.Tables["Modules"];
     this.Controls.Add(table);
     stm = "SELECT * FROM Modules WHERE year = @year";
     SQLiteCommand command = new SQLiteCommand(stm, DBSchema.connection());
     command.Parameters.Add(new SQLiteParameter("@year", year));
     SQLiteDataReader dr = command.ExecuteReader();
     modules = new List<Module>();
     while (dr.Read())
     {
         modules.Add(new Module(dr));
     }
     table.ClearSelection();
     table.CellClick += new DataGridViewCellEventHandler(this.rowSelected);
 }
Пример #6
0
 private void AddButtonClick(object sender, EventArgs e)
 {
     if (_dataGridView.Columns.Count > 0)
     {
         _dataGridView.ClearSelection();
         _dataGridView.Rows[_dataGridView.Rows.Add(_defaultValues)].Selected = true;
     }
 }
Пример #7
0
 public void AddRow(params string[] values)
 {
     if (_dataGridView.Columns.Count > 0)
     {
         _dataGridView.ClearSelection();
         _dataGridView.Rows[_dataGridView.Rows.Add(values)].Selected = true;
     }
 }
Пример #8
0
 public static void ResetSelect(DataGridView dgv)
 {
     if (dgv.Rows.Count > 0)
     {
         dgv.ClearSelection();
         dgv.Rows[0].Selected = true;
         dgv.CurrentCell = dgv.Rows[0].Cells[0];
     }
 }
Пример #9
0
        public static void customizationDataGridView(DataGridView dgv)
        {
            dgv.ClearSelection();
            dgv.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);

            for (var i = 0; i < dgv.ColumnCount; i++)
            {
                dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                dgv.Columns[i].FillWeight = 1;
            }
        }
Пример #10
0
        public GridHandler()
        {
            Control = new swf.DataGridView {
                VirtualMode                 = true,
                MultiSelect                 = false,
                SelectionMode               = swf.DataGridViewSelectionMode.FullRowSelect,
                RowHeadersVisible           = false,
                AllowUserToAddRows          = false,
                AllowUserToResizeRows       = false,
                AutoSizeColumnsMode         = swf.DataGridViewAutoSizeColumnsMode.DisplayedCells,
                ColumnHeadersHeightSizeMode = swf.DataGridViewColumnHeadersHeightSizeMode.DisableResizing
            };
            Control.CellValueNeeded += (sender, e) => {
                var item = GetItemAtRow(e.RowIndex);
                if (Widget.Columns.Count > e.ColumnIndex)
                {
                    var col = Widget.Columns[e.ColumnIndex].Handler as GridColumnHandler;
                    if (item != null && col != null)
                    {
                        e.Value = col.GetCellValue(item);
                    }
                }
            };

            Control.CellValuePushed += (sender, e) => {
                var item = GetItemAtRow(e.RowIndex);
                if (Widget.Columns.Count > e.ColumnIndex)
                {
                    var col = Widget.Columns[e.ColumnIndex].Handler as GridColumnHandler;
                    if (item != null && col != null)
                    {
                        col.SetCellValue(item, e.Value);
                    }
                }
            };
            Control.RowPostPaint += HandleRowPostPaint;

            // The DataGridView automatically selects the first row, which
            // is problematic and also not consistent across platforms.
            // So we always get rid of the first selection.
            var isFirstSelection = true;

            Control.SelectionChanged += (s, e) => {
                if (isFirstSelection)
                {
                    Control.ClearSelection();
                }
                isFirstSelection = false;
            };
        }
Пример #11
0
    private void InitializeDataGridView(string dateStr)
    {
        try
        {
            // Automatically generate the DataGridView columns.
            dataGridView1.AutoGenerateColumns = true;

            // Set up the data source.
            bindingSource1.DataSource = getDataTable(dateStr);
            dataGridView1.DataSource  = bindingSource1;

            // resize & distribute the columns in DataGridView

            // distribute size (roughyl) of datagrid by no. of columns
            int perColSize;
            if (dataGridView1.Columns.Count != 0)
            {
                perColSize = (dataGridView1.Width / dataGridView1.Columns.Count) - 1;
            }
            else             // size of the whole datagridview control
            {
                perColSize = dataGridView1.Width;
            }

            foreach (DataGridViewColumn col in dataGridView1.Columns)
            {
                col.Width = perColSize;
            }

            // // Automatically resize the visible rows.
            // dataGridView1.AutoSizeRowsMode =
            //     DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;

            // Set the DataGridView control's border.
            dataGridView1.BorderStyle = BorderStyle.Fixed3D;

            // Put the cells in edit mode when user enters them.
            dataGridView1.ReadOnly           = true;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.ClearSelection();

            this.colorCodeGrid(0, @"august", @"september");
        }
        catch
        {
            Console.WriteLine("Error with DataGridView Initialization...");
        }
    }
Пример #12
0
        private DataGridView GetDataGrid()
        {
            var dgv = new DataGridView()
            {
                BackgroundColor = Color.White,
                Location = new Point(Location.X + 5, Location.Y),
                RowHeadersVisible = false,
                Anchor = AnchorStyles.Top,
                ScrollBars = ScrollBars.None,
                AllowUserToResizeColumns = false,
                AllowUserToAddRows = false,
                AllowUserToResizeRows = false,
                AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells,
                ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing

            };

            dgv.Columns.AddRange(new DataGridViewColumn[]
                {
                    new DataGridViewTextBoxColumn() { HeaderText = "Время", Name = "timeColumn", ReadOnly = true },
                    new DataGridViewTextBoxColumn() { HeaderText = "Тип", Name = "severityColumn", ReadOnly = true },
                    new DataGridViewTextBoxColumn() { HeaderText = "Сообщение", Name = "messageColumn", ReadOnly = true }
                });

            dgv.SelectionChanged += (s, e) => dgv.ClearSelection();

            for (int i = 0; i < dgv.Columns.Count; i++)
            {
                dgv.Columns[i].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                dgv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

                if (i == dgv.Columns.Count - 1)
                {
                    dgv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                }
            }

            //dgv.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter;

            return dgv;
        }
Пример #13
0
        /// <summary>
        /// Sélectionne les lignes depuis une liste d'index
        /// </summary>
        public static void SelectRowsByIndex(this System.Windows.Forms.DataGridView iDgv, List <int> iSelectedIndex)
        {
            if (iSelectedIndex.IsNullOrEmpty())
            {
                return;
            }

            iDgv.ClearSelection();

            foreach (int Item in iSelectedIndex)
            {
                try
                {
                    iDgv.Rows[Item].Selected = true;
                }
                catch
                {
                }
            }
        }
Пример #14
0
        private void cboProvider_SelectedIndexChanged(object sender, EventArgs e)
        {
            _initialized = true;

            var    file = (String)cboProvider.SelectedItem;
            string res  = _servicesDirectory + Path.DirectorySeparatorChar + file + ".xml";

            XDocument xdoc = XDocument.Load(res);
            var       el   = xdoc.Element("Services");
            var       el1  = el.Element("TileMapService");


            using (var webClient = new WebClient())
            {
                var ms = new MemoryStream(webClient.DownloadData(el1.Attribute("href").Value));
                ms.Seek(0, SeekOrigin.Begin);
                SelectedTileMapService = TileMapService.CreateFromResource(ms);
                ms.Seek(0, SeekOrigin.Begin);
                TmsTileMapServiceXml = XDocument.Load(ms);
            }

            /*
             * var request = (HttpWebRequest)WebRequest.Create(el1.Attribute("href").Value);
             * request.UserAgent =
             *  "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14";
             * //request.Referer = ""
             * using (var response = request.GetRequestStream())
             *  SelectedTileMapService = TileMapService.CreateFromResource(response);
             */
            btnRemoveProvider.Enabled = true;

            var tileMaps = new List <TileMapItem>(SelectedTileMapService.TileMaps);

            dgvServices.DataSource = tileMaps;

            //resize columns
            dgvServices.Columns[0].Width = 120;
            dgvServices.ClearSelection();

            _initialized = false;
        }
Пример #15
0
 public static void InitDataGridView(DataGridView dgv)
 {
     //只读属性设置
     //dgv.ReadOnly = true;
     //尾行自动追加
     dgv.AllowUserToAddRows = false;
     dgv.AllowUserToDeleteRows = false;
     //行幅自动变化
     dgv.AllowUserToResizeRows = true;
     //高度设定
     dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
     //标头设定
     dgv.RowHeadersVisible = true;
     //标题行高
     dgv.ColumnHeadersHeight = 25;
     dgv.RowTemplate.Height = 23;
     //行选择设定
     dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
     //多行选择
     dgv.MultiSelect = false;
     //选择状态解除
     dgv.ClearSelection();
     //head文字居中
     dgv.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
     //选择状态的行的颜色
     dgv.DefaultCellStyle.SelectionBackColor = Color.LightSteelBlue;
     dgv.DefaultCellStyle.SelectionForeColor = Color.Black;
     //设定交替行颜色
     dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.White;
     dgv.RowsDefaultCellStyle.BackColor = Color.LightGray;
     //行副填充时自动调整宽度
     dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
     dgv.AutoGenerateColumns = false;
     //可否手动调整行大小
     dgv.AllowUserToResizeRows = false;
     dgv.AutoGenerateColumns = false;
     dgv.ScrollBars = ScrollBars.Both;
     dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
 }
Пример #16
0
 /// <summary>
 /// Selects a given row in a DataGridView. If the requested row does not
 /// exist, selects a suitable alternative.
 /// </summary>
 /// <param name="dataGridView">The DataGridView containing the row</param>
 /// <param name="row">The row to select</param>
 public static void DoRowSelection(DataGridView dataGridView, int row)
 {
     if (dataGridView.Rows.Count > 0)
     {
         dataGridView.ClearSelection();
         if (row > -1)
         {
             if (row < dataGridView.Rows.Count)
             {
                 dataGridView.Rows[row].Selected = true;
             }
             else
             {
                 dataGridView.Rows[dataGridView.Rows.Count - 1].Selected = true;
             }
         }
         else
         {
             dataGridView.Rows[0].Selected = true;
         }
     }
 }
        public Individual_Unit_Details_Panel()
        {
            InitializeComponent();

            this.HideOnClose = true;
            this.Text = "Individual Unit Details";
            this.TabText = "Individual Unit Details";
            this.ToolTipText = "Individual unit information";

            m_oArmorDisplayDataGrid = new DataGridView();
            m_oArmorDisplayDataGrid.Dock = DockStyle.Fill;
            m_oArmorDisplayDataGrid.AllowUserToAddRows = false;
            m_oArmorDisplayDataGrid.AllowUserToDeleteRows = false;
            m_oArmorDisplayDataGrid.AllowUserToOrderColumns = false;
            m_oArmorDisplayDataGrid.AllowUserToResizeColumns = false;
            m_oArmorDisplayDataGrid.AllowUserToResizeRows = false;
            m_oArmorDisplayDataGrid.Enabled = true;
            m_oArmorDisplayDataGrid.ReadOnly = true;
            m_oArmorDisplayDataGrid.ColumnHeadersVisible = false;
            m_oArmorDisplayDataGrid.RowHeadersVisible = false;
            m_oArmorDisplayDataGrid.ClearSelection();
            this.m_oArmorGroupBox.Controls.Add(m_oArmorDisplayDataGrid);
        }
Пример #18
0
        public static void updateTables(DataGridView registerTable, DataGridView memoryTable, Cpu cpu, Main comInterface)
        {
            registerTable.DataSource = null;
            registerTable.RowTemplate.Height = 16;
            registerTable.DataSource = TableFactory.getRegisterTable(cpu);

            dataGridHelper.showChanged(registerTable);

            memoryTable.DataSource = null;
            memoryTable.RowTemplate.Height = 16;
            memoryTable.DataSource = TableFactory.getMemoryTable(comInterface.Host);

            int curRow = (int) Math.Floor((double) (cpu.PC/0x10)), curCell = (cpu.PC%0x10) + 1;

            if (memoryTable.ColumnCount == 0x10 + 1)
            {
                memoryTable.CurrentCell = memoryTable.Rows[curRow].Cells[curCell];
                memoryTable.ClearSelection();
            }
            memoryTable.Rows[curRow].Cells[curCell].Style.BackColor = Color.Yellow;
            if (lastCell != null) lastCell.Style = lastRow.DefaultCellStyle;
            lastRow = memoryTable.Rows[curRow];
            lastCell = lastRow.Cells[curCell];
        }
Пример #19
0
        private void LoadFilePatterns(FilePatternList Patterns, DataGridView Destination)
        {
            foreach (FilePattern FP in Patterns)
            {
                int RowIndex = Destination.Rows.Add();
                Destination[0, RowIndex].Value = FP.Pattern;
                Destination[1, RowIndex].Value = (FP.IsValid ? "OK" : "Invalid file pattern");
            }


            Destination.ClearSelection();
            Destination.Refresh();
        }
Пример #20
0
 public void llenarDataGrid(DataGridView dg, SqlConnection conn, SqlCommand cmd)
 {
     SqlDataAdapter da = new SqlDataAdapter {SelectCommand = cmd};
     DataTable tabla = new DataTable();
     conn.Open();
     da.Fill(tabla);
     conn.Close();
     dg.DataSource = tabla;
     dg.Refresh();
     dg.ClearSelection();
 }
Пример #21
0
        private void ScrollToRow(DataGridView view, int r)
        {
            try
            {
                int row = Math.Max(0, Math.Min(r, view.RowCount - 1));

                if (row < view.RowCount)
                {
                    view.FirstDisplayedScrollingRowIndex = row;
                    view.ClearSelection();
                    view.Rows[row].Selected = true;
                }
            }
            catch (InvalidOperationException)
            {
                // this can happen when the window is too small, all we can do is ignore it.
            }
        }
Пример #22
0
        private void ScrollToRow(DataGridView view, int r)
        {
            int row = Math.Max(0, Math.Min(r, view.RowCount - 1));

            if (row < view.RowCount)
            {
                view.FirstDisplayedScrollingRowIndex = row;
                view.ClearSelection();
                view.Rows[row].Selected = true;
            }
        }
Пример #23
0
 public void FuncBusquedas(Control CtrToValidate, ErrorProvider errorprov, string TextError,
     ComboBox cb, DataGridView grv, ref string updSelected, ref string updtxtBusqueda, 
     string[] NameHeaders)
 {
     Boolean FormValido = true; //Empezamos suponiendo que el formulario es valido
     if (cb.SelectedItem.ToString() != "Ver todo")
         FormValido = Functions.ValidarControl(errorprov, CtrToValidate, TextError);
     if (FormValido)
     {
         ExecuteBusqueda(grv, cb.SelectedItem.ToString().ToUpper(), CtrToValidate.Text);
         if (grv.Rows.Count > 0)
         {
             grv.Columns[0].Visible = false;
             grv.ClearSelection();
             updSelected = cb.SelectedItem.ToString();
             updtxtBusqueda = CtrToValidate.Text;
             Functions.SetHeaderColumnsName(grv, NameHeaders, 1);
         }
     }
 }
Пример #24
0
 private void chatLog_SelectionChanged(object sender, EventArgs e)
 {
     chatLog.ClearSelection();
 }
Пример #25
0
        public void dibujar(int maxFilas, int cantHab, SqlDataReader reader)
        {
            if (tabla1.Rows.Count > 0)
            {
                tabla1.Rows.Clear();
            }
            if (tabla2 != null)
            {
                this.tableLayoutPanel3.Controls.Remove(tabla2);
                tabla2.Rows.Clear();
                tabla2 = null;
            }
            int ultFila = 0;
            while (ultFila < maxFilas && reader.Read())
            {
                DataGridViewRow row = new DataGridViewRow();
                tabla1.DefaultCellStyle.BackColor = Color.White;
                tabla1.Rows.Add(reader["nroHabitacion"], reader["categoria2"].ToString() == "" ? reader["categoria"] : reader["categoria2"]);
                ultFila = tabla1.Rows.GetLastRow(DataGridViewElementStates.None);

                if (reader["estado"].ToString() == "D") // Disponible
                {
                    tabla1.Rows[ultFila].Cells["estado"].Value = "D";

                    tabla1.Rows[ultFila].Cells["bar"].Value = ((System.Drawing.Image)Resources.vacio);
                    tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
                }
                else if (reader["estado"].ToString() == "A") // Asignada
                {
                    tabla1.Rows[ultFila].Cells["estado"].Value = "A";

                    tabla1.Rows[ultFila].DefaultCellStyle.Font = new Font(tabla1.DefaultCellStyle.Font, FontStyle.Bold);
                    //Si hay alarmas
                    if (reader["aviso"].ToString() != "")
                        tabla1.Rows[ultFila].Cells["alarma"].Value = ((System.Drawing.Image)Resources.relojdespertador);
                    tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
                }
                else if (reader["estado"].ToString() == "O") // Ocupada
                {
                    tabla1.Rows[ultFila].Cells["estado"].Value = "O";
                    tabla1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);

                    tabla1.Rows[ultFila].DefaultCellStyle.Font = new Font(tabla1.DefaultCellStyle.Font, FontStyle.Bold);
                    tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Tomato;
                    if (reader["aviso"].ToString() != "")
                        tabla1.Rows[ultFila].Cells["alarma"].Value = ((System.Drawing.Image)Resources.relojdespertador);
                }
                else if (reader["estado"].ToString() == "M") // Mucama
                {
                    tabla1.Rows[ultFila].Cells["estado"].Value = "M"; // Mucama
                    tabla1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
                    tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Yellow;
                }
                else // Otro...
                {
                    //tabla1.Rows[ultFila].DefaultCellStyle.BackColor = Color.Gainsboro;
                    tabla1.Rows[ultFila].Cells["estado"].Value = "X"; // deshabilitado
                    tabla1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.vacio);
                    tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Gainsboro;
                }
            }
            if (cantHab > maxFilas)
            {
                ultFila = 0;
                tabla2 = TablaTurnos.nuevaTabla();
                tabla2.DefaultCellStyle.BackColor = Color.White;
                tabla2.Columns[8].Visible = true;
                tabla2.Columns.RemoveAt(7);
                tabla2.Columns.RemoveAt(6);
                tabla2.DefaultCellStyle.Font = tabla1.DefaultCellStyle.Font;
                tabla2.ColumnHeadersHeight = tabla1.ColumnHeadersHeight;
                tabla2.RowTemplate.Height = tabla1.RowTemplate.Height;
                this.tableLayoutPanel3.Controls.Add(tabla2, 1, 0);

                while (reader.Read() && ultFila < 24)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    tabla2.Rows.Add(reader["nroHabitacion"], reader["categoria"]);
                    ultFila = tabla2.Rows.GetLastRow(DataGridViewElementStates.None);

                    if (reader["estado"].ToString() == "D")
                    {
                        tabla2.Rows[ultFila].Cells["estado"].Value = "D";

                        tabla2.Rows[ultFila].Cells["bar"].Value = ((System.Drawing.Image)Resources.vacio);
                        tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
                    }
                    else if (reader["estado"].ToString() == "A")
                    {
                        tabla2.Rows[ultFila].Cells["estado"].Value = "A";

                        tabla2.Rows[ultFila].DefaultCellStyle.Font = new Font(tabla1.DefaultCellStyle.Font, FontStyle.Bold);
                        //Si hay alarmas
                        if (reader["aviso"].ToString() != "")
                            tabla2.Rows[ultFila].Cells["alarma"].Value = ((System.Drawing.Image)Resources.relojdespertador);
                        tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
                    }
                    else if (reader["estado"].ToString() == "O") // Ocupada
                    {
                        tabla2.Rows[ultFila].Cells["estado"].Value = "O";
                        tabla2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);

                        tabla2.Rows[ultFila].DefaultCellStyle.Font = new Font(tabla2.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold);
                        tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Tomato;
                        if (reader["aviso"].ToString() != "")
                            tabla2.Rows[ultFila].Cells["alarma"].Value = ((System.Drawing.Image)Resources.relojdespertador);
                    }
                    else if (reader["estado"].ToString() == "M") // Mucama
                    {
                        tabla2.Rows[ultFila].Cells["estado"].Value = "M"; // Mucama
                        tabla2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
                        tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Yellow;
                    }
                    else // Otro...
                    {
                        //tabla2.Rows[ultFila].DefaultCellStyle.BackColor = Color.Gainsboro;
                        tabla2.Rows[ultFila].Cells["estado"].Value = "X"; // deshabilitado
                        tabla2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.vacio);
                        tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Gainsboro;
                    }
                }
                tabla2.ClearSelection();
            }
            tabla1.ClearSelection();
            reader.Close();
        }
Пример #26
0
        private void ShowResultMulitGrid(DataSet ds)
        {
            var tabControl = new TabControl();
            tabControl.Dock = DockStyle.Fill;
            this.panelMain.Controls.Add(tabControl);
            for (var i = 0; i < ds.Tables.Count; i++)
            {

                var grid = new DataGridView();
                grid.ClearSelection();

                grid.ReadOnly = true;
                grid.Dock = DockStyle.Fill;
                grid.DataSource = ds.Tables[i];
                grid.RowHeadersVisible = false;
                grid.AllowUserToAddRows = false;
                grid.CellPainting += Grid_CellPainting;

                grid.ClearSelection();

                var tabPage = new System.Windows.Forms.TabPage();
                tabPage.Text = ds.Tables[i].TableName;
                tabPage.Controls.Add(grid);
                tabControl.TabPages.Add(tabPage);
            }
        }
Пример #27
0
 public void FuncBusquedas(Control CtrToValidate, ErrorProvider oError, string TextError,
     ComboBox cb, DataGridView grv, ref string updSelected, ref string updtxtBusqueda, 
     string[] NameHeaders, string Type_Op)
 {
     Boolean FormValido = true; //Empezamos suponiendo que el formulario es valido
     if (cb.SelectedItem.ToString()!="Ver todo")
         FormValido = Functions.ValidarControl(oError, CtrToValidate, "Busqueda requerido");
     if (FormValido)
     {
         ExecuteBusqueda(grv, cb.SelectedItem.ToString().ToUpper(), CtrToValidate.Text, Type_Op);
         Functions.SetHeaderColumnsName(grv, NameHeaders, 1);
         if (grv.Rows.Count > 0)
         {
             grv.Columns[0].Visible = false;
             //grv.Columns[1].Visible = false; //Oculta la columna Id
             grv.Columns[2].Visible = false; //oculta la columna Fecha Transaccion
             grv.ClearSelection();
             updSelected = cb.SelectedItem.ToString();
             updtxtBusqueda = CtrToValidate.Text;
         }
     }
 }
Пример #28
0
        private void FormAsignarHab_Load(object sender, EventArgs e)
        {
            int altoFilaExtraMedioPagos;
            tabla1 = TablaTurnos.nuevaTabla();
            tabla2 = TablaTurnos.nuevaTabla();

            tabla1.DefaultCellStyle.BackColor = Color.White;
            tabla2.DefaultCellStyle.BackColor = Color.White;
            tabla2.Columns[8].Visible = tabla1.Columns[8].Visible = true;

            this.tableLayoutPanel3.Controls.Add(tabla1, 0, 0);

            int altoFila;
            int altoFilaExtra;
            tools.calcularAlturas(tabla1.Height - tabla1.ColumnHeadersHeight, fPrincipal2.maxFilas, out altoFila, out altoFilaExtra);
            tabla1.RowTemplate.Height = altoFila;
            tabla2.RowTemplate.Height = altoFila;
            tabla1.ColumnHeadersHeight = tabla1.ColumnHeadersHeight + altoFilaExtra;
            tabla2.ColumnHeadersHeight = tabla1.ColumnHeadersHeight;
            float tamFuente = 10f + (3.6f - (0.1f * cantHab));
            tabla1.DefaultCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", tamFuente, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            tabla2.DefaultCellStyle.Font = tabla1.DefaultCellStyle.Font;
            this.tableLayoutPanel3.Controls.Add(tabla2, 1, 0);

            tools.actualizarListadoTurnos(tabla1, tabla2);
            tabla1.Columns.RemoveAt(7);
            tabla1.Columns.RemoveAt(6);
            tabla2.Columns.RemoveAt(7);
            tabla2.Columns.RemoveAt(6);

            tools.calcularAlturas(dgvOpciones.Height - dgvOpciones.ColumnHeadersHeight, opcionesCambEst.opcionesCambioEstado.Count > tools.minCantFilas ? opcionesCambEst.opcionesCambioEstado.Count : tools.minCantFilas, out altoFila, out altoFilaExtraMedioPagos);
            dgvOpciones.RowTemplate.Height = altoFila;
            this.opcionesCambioEstadoTableAdapter.Fill(this.opcionesCambEst.opcionesCambioEstado);
            dgvOpciones.DataSource = null;
            foreach (DataRow dr in opcionesCambEst.opcionesCambioEstado)
            {
                dOpciones.Add(int.Parse(dr[0].ToString()), dr[1].ToString());
                dgvOpciones.Rows.Add(dr[0].ToString(), dr[1].ToString());
            }

            // ----  Completando la tabla mediosPagos  ----//
            tools.completarDG(dgvOpciones, altoFilaExtraMedioPagos);
            dgvOpciones.ClearSelection();
            tabla1.ClearSelection();
            tabla2.ClearSelection();
        }
Пример #29
0
        public void dibujar_bk(int maxFilas, int cantHab, SqlDataReader reader)
        {
            mut.WaitOne();

            if (dataGridView1.Rows.Count > 0)
            {
                dataGridView1.Rows.Clear();
                dataGridView1.Controls.Clear();
            }
            if (col2 != null)
            {
                this.tableLayoutPanel1.Controls.Remove(col2);
                col2.Rows.Clear();
                col2 = null;
            }
            int ultFila = 0;
            while (ultFila < maxFilas && reader.Read())
            {
            //                DataGridViewRow row = new DataGridViewRow();
                dataGridView1.Rows.Add(reader["nroHabitacion"], reader["categoria2"].ToString() == "" ? reader["categoria"] : reader["categoria2"]);
                ultFila = dataGridView1.Rows.GetLastRow(DataGridViewElementStates.None);

                dataGridView1.Rows[ultFila].Cells["importe"].Value = String.Format("{0:C}", reader["importe"]);

                //---  Seteo el reloj para las alarmas  ---//
                if (reader["estado"].ToString() == "A" || reader["estado"].ToString() == "O")
                {
                    //---  Si hay alarmas ---//
                    if (dicAlarmasSonando.ContainsKey(int.Parse(reader["nroHabitacion"].ToString())))
                    {
                        PictureBox pb = new PictureBox();
                        pb.Size = dataGridView1.GetCellDisplayRectangle(4, 0, true).Size;
                        pb.Image = Resources.relojSonando_2;
                        pb.SizeMode = PictureBoxSizeMode.Zoom;
                        pb.BackColor = Color.Transparent;
                        pb.Location = dataGridView1.GetCellDisplayRectangle(4, dataGridView1.Rows[ultFila].Index, true).Location;
                        //if (dataGridView1.Controls.Contains(dicAlarmasSonando[int.Parse(reader["nroHabitacion"].ToString())]))
                        //    dataGridView1.Controls.Remove(dicAlarmasSonando[int.Parse(reader["nroHabitacion"].ToString())]);
                        dataGridView1.Controls.Add(pb);
                    }
                    else
                    {
                        if (reader["aviso"].ToString() != "")
                            dataGridView1.Rows[ultFila].Cells["alarma"].Value = Resources.relojSonando_2;
                    }
                }

                if (reader["estado"].ToString() == "D") // Disponible
                {
                    dataGridView1.Rows[ultFila].Cells["estado"].Value = "D";
                    dataGridView1.Rows[ultFila].Cells["salida"].Value = "";
                    dataGridView1.Rows[ultFila].Cells["bar"].Value = ((System.Drawing.Image)Resources.vacio);
                    dataGridView1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;

                }
                else if (reader["estado"].ToString() == "A") // Asignada
                {
                    dataGridView1.Rows[ultFila].Cells["estado"].Value = "A";
                    dataGridView1.Rows[ultFila].Cells["salida"].Value = (DateTime.Parse(reader["hsalida"].ToString())).ToString("HH:mm");
                    dataGridView1.Rows[ultFila].DefaultCellStyle.Font = new Font(dataGridView1.DefaultCellStyle.Font, FontStyle.Bold);
                    dataGridView1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
                }
                else if (reader["estado"].ToString() == "O") // Ocupada
                {
                    dataGridView1.Rows[ultFila].Cells["estado"].Value = "O";
                    dataGridView1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
                    dataGridView1.Rows[ultFila].Cells["salida"].Value = (DateTime.Parse(reader["hsalida"].ToString())).ToString("HH:mm");
                    dataGridView1.Rows[ultFila].DefaultCellStyle.Font = new Font(dataGridView1.DefaultCellStyle.Font, FontStyle.Bold);
                    dataGridView1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Tomato;
                    //if (reader["aviso"].ToString() != "")
                    //    if (!dicAlarmasSonando.ContainsKey(int.Parse(reader["nroHabitacion"].ToString())))
                    //        dataGridView1.Rows[ultFila].Cells["alarma"].Value = Resources.relojSonando_2;
                }
                else if (reader["estado"].ToString() == "M") // Mucama
                {
                    dataGridView1.Rows[ultFila].Cells["estado"].Value = "M"; // Mucama
                    dataGridView1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
                    dataGridView1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Yellow;
                }
                else // Otro...
                {
                    //dataGridView1.Rows[ultFila].DefaultCellStyle.BackColor = Color.Gainsboro;
                    dataGridView1.Rows[ultFila].Cells["estado"].Value = "X"; // deshabilitado
                    dataGridView1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.vacio);
                    dataGridView1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Gainsboro;
                }
            }
            if (cantHab > maxFilas)
            {
                ultFila = 0;
                col2 = TablaTurnos.nuevaTabla();
                col2.DefaultCellStyle.Font = dataGridView1.DefaultCellStyle.Font;
                col2.ColumnHeadersHeight = dataGridView1.ColumnHeadersHeight;
                col2.RowTemplate.Height = dataGridView1.RowTemplate.Height;
                this.tableLayoutPanel1.Controls.Add(col2, 1, 1);
                this.tableLayoutPanel1.SetRowSpan(col2, 2);
                while (reader.Read() && ultFila < 24)
                {
                    //DataGridViewRow row = new DataGridViewRow();
                    col2.Rows.Add(reader["nroHabitacion"], reader["categoria"]);
                    ultFila = col2.Rows.GetLastRow(DataGridViewElementStates.None);

                    col2.Rows[ultFila].Cells["importe"].Value = String.Format("{0:C}", reader["importe"]);

                    //---  Seteo el reloj para las alarmas  ---//
                    if (reader["estado"].ToString() == "A" || reader["estado"].ToString() == "O")
                    {
                        //---  Si hay alarmas ---//
                        if (dicAlarmasSonando.ContainsKey(int.Parse(reader["nroHabitacion"].ToString())))
                        {
                            PictureBox pb = new PictureBox();
                            pb.Size = dataGridView1.GetCellDisplayRectangle(4, 0, true).Size;
                            pb.Image = Resources.relojSonando_2;
                            pb.SizeMode = PictureBoxSizeMode.Zoom;
                            pb.BackColor = Color.Transparent;
                            pb.Location = dataGridView1.GetCellDisplayRectangle(4, col2.Rows[ultFila].Index, true).Location;
                            if (col2.Controls.Contains(dicAlarmasSonando[int.Parse(reader["nroHabitacion"].ToString())]))
                                col2.Controls.Remove(dicAlarmasSonando[int.Parse(reader["nroHabitacion"].ToString())]);
                            col2.Controls.Add(pb);
                        }
                        else
                        {
                            if (reader["aviso"].ToString() != "")
                                col2.Rows[ultFila].Cells["alarma"].Value = Resources.relojSonando_2;
                        }
                    }

                    if (reader["estado"].ToString() == "D")
                    {
                        col2.Rows[ultFila].Cells["estado"].Value = "D";
                        col2.Rows[ultFila].Cells["salida"].Value = "";
                        col2.Rows[ultFila].Cells["bar"].Value = ((System.Drawing.Image)Resources.vacio);
                        col2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
                    }
                    else if (reader["estado"].ToString() == "A")
                    {
                        col2.Rows[ultFila].Cells["estado"].Value = "A";
                        col2.Rows[ultFila].Cells["salida"].Value = (DateTime.Parse(reader["hsalida"].ToString())).ToString("HH:mm");
                        col2.Rows[ultFila].DefaultCellStyle.Font = new Font(dataGridView1.DefaultCellStyle.Font, FontStyle.Bold);
                        col2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
                        ////Si hay alarmas
                        //if (reader["aviso"].ToString() != "")
                        //    if (!dicAlarmasSonando.ContainsKey(int.Parse(reader["nroHabitacion"].ToString())))
                        //        col2.Rows[ultFila].Cells["alarma"].Value = Resources.relojSonando_2;

                    }
                    else if (reader["estado"].ToString() == "O") // Ocupada
                    {
                        col2.Rows[ultFila].Cells["estado"].Value = "O";
                        col2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
                        col2.Rows[ultFila].Cells["salida"].Value = (DateTime.Parse(reader["hsalida"].ToString())).ToString("HH:mm");
                        col2.Rows[ultFila].DefaultCellStyle.Font = new Font(col2.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold);
                        col2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Tomato;
                        //if (reader["aviso"].ToString() != "")
                        //    if (!dicAlarmasSonando.ContainsKey(int.Parse(reader["nroHabitacion"].ToString())))
                        //        col2.Rows[ultFila].Cells["alarma"].Value = Resources.relojSonando_2;
                    }
                    else if (reader["estado"].ToString() == "M") // Mucama
                    {
                        col2.Rows[ultFila].Cells["estado"].Value = "M"; // Mucama
                        col2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
                        col2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Yellow;
                    }
                    else // Otro...
                    {
                        //col2.Rows[ultFila].DefaultCellStyle.BackColor = Color.Gainsboro;
                        col2.Rows[ultFila].Cells["estado"].Value = "X"; // deshabilitado
                        col2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.vacio);
                        col2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Gainsboro;
                    }
                }
                col2.ClearSelection();
            }
            dataGridView1.ClearSelection();
            reader.Close();
            dataGridView1.DataSource = null;
            col2 = null;
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            mut.ReleaseMutex();
        }
Пример #30
0
        private void SearchInDataGrid(string searchText,bool caseSensitive, DataGridView grid)
        {
            Regex regex = new Regex(searchText, caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
            for (int i = foundIndex; i < grid.Rows.Count && !found; i++) {
                if (regex.Matches(grid.Rows[i].Cells[3].Value.ToString()).Count > 0) {
                    grid.ClearSelection();
                    DataGridViewCellStyle style = new DataGridViewCellStyle();
                    style.BackColor = Color.LightGreen;
                    grid.Rows[i].Selected = true;
                    grid.FirstDisplayedScrollingRowIndex = i;
                    found = true;
                    foundIndex = i;
                }
            }
            if (!found && foundIndex > -1) {
                foundIndex = -1;
            }

            found = false;
            cboFindText.Items.Add(cboFindText.Text);
        }
 public void DisableSelected(System.Windows.Forms.DataGridView dgv)
 {
     dgv.ClearSelection();
 }
        public void UpdateWeaponTextFields(Dictionary<string, Weapon> weapons, DataGridView gridView)
        {
            gridView.Columns.Clear();

            gridView.Columns.Add("nameCol", "Name");
            gridView.Columns.Add("killsCol", "Kills");
            gridView.Columns.Add("hsPercentCol", "HS%");
            gridView.Columns.Add("accuracyCol", "Acc");
            gridView.Columns.Add("headShotCol", "HS");
            gridView.Columns.Add("fireCountCol", "Fired");
            gridView.Columns.Add("hitsCount", "Hits");

            for (int i = 1; i < gridView.ColumnCount; i++)
            {
                // Resize columns.
                gridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            }

            // Set the HSR/ACC column to wrap text.
            gridView.Columns[2].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            gridView.Columns[3].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

            // Resize the rows.
            gridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;

            // Add all rows before iterating through them.
            if (weapons.Count == 0) return;

            gridView.Rows.Add(weapons.Count);

            for (int i = 0; i < weapons.Count; i++)
            {
                Weapon weapon = weapons.ElementAt(i).Value;
                gridView.Rows[i].Cells[0].Value = weapon.name;
                gridView.Rows[i].Cells[1].Value = weapon.kills;

                // Calculate acc change.
                float currentACC = weapon.hitsCount / weapon.fireCount;
                string accStr = currentACC.ToString("#0.###%");
                // Calculate hsr change.
                float currentHSR = weapon.headShots / weapon.kills;
                string hsrStr = currentHSR.ToString("#0.###%");
                if (gridView.Name == "sessionWeaponsGridView" && m_sessionStarted)
                {
                    // HSR
                    float[] absHSR = GetWeaponHSR(weapon.name, m_sesStartWeapons);
                    float oldTotalHSR = absHSR[0] / (absHSR[1] == 0.0f ? 1 : absHSR[1]);
                    absHSR[0] += weapon.headShots;
                    absHSR[1] += weapon.kills;
                    float newTotalHSR = absHSR[0] / (absHSR[1] == 0.0f ? 1 : absHSR[1]);
                    float hsrDif = newTotalHSR - oldTotalHSR;

                    hsrStr += "\n" + newTotalHSR.ToString("#0.###%") + " " + hsrDif.ToString("+#0.###%; -#0.###%");

                    if (hsrDif < 0)
                        gridView.Rows[i].Cells[2].Style.ForeColor = m_lowColor;
                    else if (hsrDif > 0)
                        gridView.Rows[i].Cells[2].Style.ForeColor = m_highColor;
                    else
                        gridView.Rows[i].Cells[2].Style.ForeColor = Color.Black;

                    // ACC
                    float[] absACC = GetWeaponACC(weapon.name, m_sesStartWeapons);
                    float oldTotalACC = absACC[0] / (absACC[1] == 0.0f ? 1 : absACC[1]);
                    absACC[0] += weapon.hitsCount;
                    absACC[1] += weapon.fireCount;
                    float newTotalACC = absACC[0] / (absACC[1] == 0.0f ? 1 : absACC[1]);
                    float accDif = newTotalACC - oldTotalACC;

                    accStr += "\n" + newTotalACC.ToString("#0.###%") + " " + accDif.ToString("+#0.###%; -#0.###%");

                    if (accDif < 0)
                        gridView.Rows[i].Cells[3].Style.ForeColor = m_lowColor;
                    else if (accDif > 0)
                        gridView.Rows[i].Cells[3].Style.ForeColor = m_highColor;
                    else
                        gridView.Rows[i].Cells[3].Style.ForeColor = Color.Black;
                }

                gridView.Rows[i].Cells[2].Value = hsrStr;
                gridView.Rows[i].Cells[3].Value = accStr;
                gridView.Rows[i].Cells[4].Value = weapon.headShots;
                gridView.Rows[i].Cells[5].Value = weapon.fireCount;
                gridView.Rows[i].Cells[6].Value = weapon.hitsCount;
            }

            gridView.ClearSelection();
        }
 private static void SetSelectedItemDataGridView(IBindingMemberInfo bindingMemberInfo, DataGridView dataGridView, object item)
 {
     dataGridView.ClearSelection();
     if (item == null)
         return;
     for (int i = 0; i < dataGridView.Rows.Count; i++)
     {
         if (Equals(dataGridView.Rows[i].DataBoundItem, item))
         {
             var row = dataGridView.Rows[i];
             row.Selected = true;
             if (row.Cells.Count > 0)
                 row.Cells[0].Selected = true;
             break;
         }
     }
 }
Пример #34
0
    private void MoveEncodersDown(DataGridView grid, BindingList<DisplaySoftwareEncoder> list)
    {
      DataGridViewSelectedRowCollection srows = grid.SelectedRows;
      List<int> indices = new List<int>();
      if (srows.Count == 0)
      {
        return;
      }

      // Juggle rows...
      for (int i = srows.Count - 1; i >= 0; i--)
      {
        int index = srows[i].Index;
        indices.Add(index);
        if (index < grid.Rows.Count - 1)
        {
          list[index].Priority = (Convert.ToInt32(list[index].Priority) + 1).ToString();
          list[index + 1].Priority = (Convert.ToInt32(list[index + 1].Priority) - 1).ToString();
          DisplaySoftwareEncoder item = list[index + 1];
          list.RemoveAt(index + 1);
          list.Insert(index, item);
        }
      }

      // Maintain selection...
      grid.ClearSelection();
      for (int i = indices.Count - 1; i >= 0; i--)
      {
        int index = indices[i];
        if (index == grid.Rows.Count - 1)
        {
          grid.Rows[index].Selected = true;
        }
        else
        {
          grid.Rows[index + 1].Selected = true;
        }
      }
    }
Пример #35
0
 // =================================================================================
 // Scrolling & arranging datagridviews...
 // =================================================================================
 private void DataGrid_Up_button(DataGridView Grid)
 {
     int row = Grid.CurrentCell.RowIndex;
     int col = Grid.CurrentCell.ColumnIndex;
     if (row == 0)
     {
         return;
     }
     if (Grid.SelectedCells.Count != 1)
     {
         return;
     }
     DataGridViewRow temp = Grid.Rows[row];
     Grid.Rows.Remove(Grid.Rows[row]);
     Grid.Rows.Insert(row - 1, temp);
     Grid.ClearSelection();
     Grid.CurrentCell = Grid[col, row - 1];
     HandleGridScrolling(true, Grid);
 }
Пример #36
0
        // LOAD DATA
        private void loadDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // ASK FOR FILE NAME
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                MessageBox.Show("File not opened. No file name specified.");
                return;
            }
            this.squadBuilderManager.CreateDefaultObjects();
            string filename = openFileDialog1.FileName;

            // FORCE TO TURN OFF COLLECTIONS.
            this.cBox_CollectionFilter.CheckState = CheckState.Unchecked;
            this.cBox_CollectionFilter_CheckedChanged(null, null);

            // Read the file and display it line by line.
            string line;
            System.IO.StreamReader file = new System.IO.StreamReader(@filename);
            while ((line = file.ReadLine()) != null)
            {
                string[] args = line.Split('|');
                //this.tabControl1.SelectTab(args[0].ToString());

                DataGridView workingDataGridView = new DataGridView();
                switch (args[0].ToLower())
                {
                    case "ships":
                        tabControl1.SelectedTab = this.tabPage1;
                        workingDataGridView = this.dataGridView_Ships;
                        break;

                    case "captains":
                        tabControl1.SelectedTab = this.tabPage2;
                        workingDataGridView = this.dataGridView_Captains;
                        break;

                    case "upgrades":
                        tabControl1.SelectedTab = this.tabPage3;
                        workingDataGridView = this.dataGridView_Upgrades;
                        break;

                    case "resources":
                        tabControl1.SelectedTab = this.tabPage4;
                        workingDataGridView = this.dataGridView_Resources;
                        break;
                }

                workingDataGridView.ClearSelection();

                int rowIndex = -1;
                if (args[2] != "")  //IF A SUB OBJECT IS POPULATED, SET IT UP
                {

                    foreach (DataGridViewRow row in workingDataGridView.Rows)
                    {
                        if (row.Cells[0].Value.ToString().Equals(args[2]))
                        {
                            rowIndex = row.Index;
                            break;
                        }
                    }

                    if (rowIndex == -1)
                    {
                        MessageBox.Show("ERROR - Items in save file do not match current collection.");
                        toolStripMenuItem3_Click(null, null); // FORCE A NEW
                        return;
                    }

                    workingDataGridView.Rows[rowIndex].Selected = true;
                    btn_AddItem_Click(null, null);
                }
            }

            file.Close();
        }
Пример #37
0
 private void DataGrid_Down_button(DataGridView Grid)
 {
     int row = Grid.CurrentCell.RowIndex;
     int col = Grid.CurrentCell.ColumnIndex;
     int i = Grid.RowCount;
     if (row == Grid.RowCount - 1)
     {
         return;
     }
     if (Grid.SelectedCells.Count != 1)
     {
         return;
     }
     DataGridViewRow temp = Grid.Rows[row];
     Grid.Rows.Remove(Grid.Rows[row]);
     Grid.Rows.Insert(row + 1, temp);
     Grid.ClearSelection();
     Grid.CurrentCell = Grid[col, row + 1];
     Grid.Rows[row + 1].Cells[col].Selected = true;
     HandleGridScrolling(false, Grid);
 }
Пример #38
0
 public void SetCurrentRow(DataGridView _dgvLogData, int iRowCnt, int iMaxLogCnt, int iAddCnt)
 {
     try
     {
         if (iAddCnt >= iMaxLogCnt)
         {
             _dgvLogData.ClearSelection();
             _dgvLogData.CurrentCell = null;
         }
         else if (_dgvLogData.CurrentCell.RowIndex >= ((iMaxLogCnt - iAddCnt) - 1))
         {
             _dgvLogData.ClearSelection();
             _dgvLogData.CurrentCell = null;
         }
         else if (_dgvLogData.SelectedRows.Count > 0)
         {
             int rowIndex = _dgvLogData.CurrentCell.RowIndex;
             if (rowIndex >= _dgvLogData.Rows.Count)
             {
                 _dgvLogData.ClearSelection();
             }
             else
             {
                 rowIndex += iAddCnt;
                 _dgvLogData.CurrentCell = _dgvLogData.Rows[rowIndex].Cells[_dgvLogData.FirstDisplayedCell.ColumnIndex];
             }
         }
     }
     catch
     {
     }
 }
Пример #39
0
 public static void JumpToLastRow(DataGridView dgv)
 {
     int jumpToRow = dgv.Rows.GetLastRow(DataGridViewElementStates.None);
     if (dgv.Rows.Count >= jumpToRow && jumpToRow >= 1)
     {
         dgv.FirstDisplayedScrollingRowIndex = jumpToRow;
         dgv.ClearSelection();
         dgv.Rows[jumpToRow].Selected = true;
     }
 }