当前位置: 首页>>代码示例>>C#>>正文


C# DataGridView.UpdateCellValue方法代码示例

本文整理汇总了C#中System.Windows.Forms.DataGridView.UpdateCellValue方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.UpdateCellValue方法的具体用法?C# DataGridView.UpdateCellValue怎么用?C# DataGridView.UpdateCellValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.DataGridView的用法示例。


在下文中一共展示了DataGridView.UpdateCellValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessDGVEditShortcutKeys

        public bool ProcessDGVEditShortcutKeys(DataGridView dgv, KeyEventArgs e, string cno, LookupTables lookupTables, AppSettings appSettings)
        {
            bool keyProcessed = false;

            // Change cursor to the wait cursor...
            Cursor origCursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            if (e.KeyCode == Keys.D && e.Control)
            {
                Dictionary<int, int> selectedColumnMinRow = new Dictionary<int, int>();

                // Processing keystroke...
                keyProcessed = true;

                foreach (DataGridViewCell cell in dgv.SelectedCells)
                {
                    // If the min selected row has not been found for this column - find it now...
                    if (!selectedColumnMinRow.ContainsKey(cell.ColumnIndex))
                    {
                        int minRow = dgv.Rows.Count; ;
                        // Find the minimum row index in this column's selected cells...
                        minRow = cell.RowIndex;
                        for (int i = minRow; i > -1; i--)
                        {
                            if (dgv.SelectedCells.Contains(dgv[cell.ColumnIndex, i])) minRow = i;
                        }
                        // If the user is trying to perform a copy down (CTRL+D) using the row for adding a new row as the source row - bail out now...
                        if (dgv.Rows[minRow].IsNewRow) return false;

                        //Save the min row for this column in the dictionary
                        selectedColumnMinRow.Add(cell.ColumnIndex, minRow);
                    }

                    //
                    object newValue = ((DataRowView)dgv.Rows[selectedColumnMinRow[cell.ColumnIndex]].DataBoundItem)[cell.ColumnIndex];
                    DataRowView dr = (DataRowView)cell.OwningRow.DataBoundItem;
                    if (dr == null) //if (dgv.Rows[row].IsNewRow)
                    {
                        // Couldn't find a bound row so this must be the 'new row' row in the datagrid...
                        dgv[cell.ColumnIndex, cell.RowIndex].Value = newValue;
                        dgv.UpdateCellValue(cell.ColumnIndex, cell.RowIndex);
                    }
                    else
                    {
                        if (!dr[cell.ColumnIndex].Equals(newValue))
                        {
                            // Edit the DataRow (not the DataRowView) so that row state is changed...
                            dr.Row[cell.ColumnIndex] = newValue;
                        }
                    }
                }
            }

            if (e.KeyCode == Keys.E && e.Control)
            {
                // Processing keystroke...
                keyProcessed = true;

                DataRow dr = ((DataRowView)dgv.CurrentCell.OwningRow.DataBoundItem).Row;
                string columnName = dgv.CurrentCell.OwningColumn.Name;
                if (dr.Table.Columns[columnName].ExtendedProperties.ContainsKey("gui_hint") &&
                    dr.Table.Columns[columnName].ExtendedProperties["gui_hint"].ToString().ToUpper() == "TEXT_CONTROL")
                {
                    string currentCellValue = dr[columnName].ToString();
                    RichTextEditor rte = new RichTextEditor(currentCellValue, false);
                    if (rte.ShowDialog() == DialogResult.OK)
                    {
                        dr[columnName] = rte.RichTextMessage;
                    }
                }
            }

            if (e.KeyCode == Keys.N && e.Control)
            {
                if (dgv.CurrentRow != null &&
                    dgv.CurrentRow.Selected &&
                    !dgv.CurrentRow.IsNewRow)
                {
                    DataTable dt = (DataTable)((BindingSource)dgv.DataSource).DataSource;
                    DataRow sourceRow = null;
                    DataRow destRow = null;

                    // Processing keystroke...
                    keyProcessed = true;

                    if (dt != null)
                    {
                        sourceRow = dt.DefaultView[dgv.CurrentRow.Index].Row;
                        destRow = dt.NewRow();
                    }
                    if (sourceRow != null)
                    {
                        foreach (DataColumn dc in dt.Columns)
                        {
                            if (!dt.PrimaryKey.Contains(dc) &&
                                !dc.ReadOnly)
                            {
                                switch (dc.ColumnName)
                                {
//.........这里部分代码省略.........
开发者ID:egacheru,项目名称:G2,代码行数:101,代码来源:UserInterfaceUtils.cs

示例2: UpdateGridRowCells

        /// <summary>
        /// void UpdateGridRowCells(DataGridView _grid)
        /// Update the columns for the passed grid
        /// </summary>
        /// <param name="_grid"></param>
        public static void UpdateGridRowCells(DataGridView _grid)
        {
            try
            {
                _grid.EndEdit();
                for (int n = 0; n < _grid.RowCount; n++)
                {
                    for (int m = 0; m < _grid.Columns.Count; m++)
                    {
                        _grid.UpdateCellValue(m, n);
                    }
                }
            }
            catch (Exception ex)
            {
                CommonRoutines.Log("$E:" + moduleName + ".UpdateGridRowCells > " + ex.Message);
            }

            return;
        }
开发者ID:steven-e-smith,项目名称:igenfuels-igenformsviewer,代码行数:25,代码来源:CommonRoutines.cs


注:本文中的System.Windows.Forms.DataGridView.UpdateCellValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。