本文整理汇总了C#中System.Windows.Forms.DataGridView.BeginEdit方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.BeginEdit方法的具体用法?C# DataGridView.BeginEdit怎么用?C# DataGridView.BeginEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.BeginEdit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditingControlShowingTest_Bound
[Test] // Xamarin bug 5419
public void EditingControlShowingTest_Bound ()
{
using (DataGridView _dataGridView = new DataGridView ()) {
DataGridViewComboBoxColumn _nameComboBoxColumn;
DataGridViewTextBoxColumn _firstNameTextBoxColumn;
DataGridViewCheckBoxColumn _chosenCheckBoxColumn;
_dataGridView.AutoGenerateColumns = false;
// Add the event-handler.
_dataGridView.EditingControlShowing
+= new DataGridViewEditingControlShowingEventHandler
(DataGridView_EditingControlShowingTest);
// No columns have been found in the event-handler yet.
editingControlShowingTest_FoundColumns = 0;
// _nameComboBoxColumn
_nameComboBoxColumn = new DataGridViewComboBoxColumn ();
_nameComboBoxColumn.HeaderText = "Name";
_nameComboBoxColumn.DataPropertyName = "Name";
_dataGridView.Columns.Add (_nameComboBoxColumn);
// _firstNameTextBoxColumn
_firstNameTextBoxColumn = new DataGridViewTextBoxColumn ();
_firstNameTextBoxColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
_firstNameTextBoxColumn.HeaderText = "First Name";
_firstNameTextBoxColumn.DataPropertyName = "FirstName";
_dataGridView.Columns.Add (_firstNameTextBoxColumn);
// _chosenCheckBoxColumn
_chosenCheckBoxColumn = new DataGridViewCheckBoxColumn ();
_chosenCheckBoxColumn.HeaderText = "Chosen";
_chosenCheckBoxColumn.DataPropertyName = "Chosen";
_chosenCheckBoxColumn.FalseValue = "false";
_chosenCheckBoxColumn.TrueValue = "true";
_dataGridView.Columns.Add (_chosenCheckBoxColumn);
// .NET requires that all possible values for combo-boxes in a column
// are added to the column.
_nameComboBoxColumn.Items.Add ("de Icaza");
_nameComboBoxColumn.Items.Add ("Toshok");
_nameComboBoxColumn.Items.Add ("Harper");
_nameComboBoxColumn.Items.Add ("Boswell");
// Set up the contents of the data-grid.
BindingList<EcstRecord> boundData = new BindingList<EcstRecord> ();
boundData.Add (new EcstRecord ("de Icaza", "Miguel", true));
boundData.Add (new EcstRecord ("Toshok", "Chris", false));
boundData.Add (new EcstRecord ("Harper", "Jackson", false));
boundData.Add (new EcstRecord ("Boswell", "Steven", true));
_dataGridView.DataSource = boundData;
// For data binding to work, there needs to be a Form, apparently.
Form form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (_dataGridView);
form.Show ();
// Make sure the data-source took.
// (Without the Form, instead of having four rows, the data grid
// only has one row, and all its cell values are null.)
Assert.AreEqual (boundData.Count, _dataGridView.Rows.Count, "1-6");
// Edit a combo-box cell.
_dataGridView.CurrentCell = _dataGridView.Rows[3].Cells[0];
Assert.AreEqual (true, _dataGridView.Rows[3].Cells[0].Selected, "1-7");
Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-8");
_dataGridView.CancelEdit();
// Edit a text-box cell.
_dataGridView.CurrentCell = _dataGridView.Rows[0].Cells[1];
Assert.AreEqual (false, _dataGridView.Rows[3].Cells[0].Selected, "1-9");
Assert.AreEqual (true, _dataGridView.Rows[0].Cells[1].Selected, "1-10");
Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-11");
_dataGridView.CancelEdit();
// Edit a check-box cell.
_dataGridView.CurrentCell = _dataGridView.Rows[3].Cells[2];
Assert.AreEqual (false, _dataGridView.Rows[0].Cells[1].Selected, "1-12");
Assert.AreEqual (true, _dataGridView.Rows[3].Cells[2].Selected, "1-13");
Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-14");
_dataGridView.CancelEdit();
// Make sure the event-handler was called each time.
// (DataGridViewCheckBoxCell isn't derived from Control, so the
// EditingControlShowing event doesn't get called for it.)
Assert.AreEqual (3, editingControlShowingTest_FoundColumns, "1-14");
// Get rid of the form.
form.Close();
}
}
示例2: SetEditMode
private void SetEditMode(DataGridView dataGridView)
{
if (dataGridView.SelectedCells.Count > 0)
{
DataGridViewCell cell = dataGridView.SelectedCells[0];
dataGridView.CurrentCell = cell;
dataGridView.BeginEdit(true);
}
}
示例3: EditingControlShowingTest_Unbound
[Test] // Xamarin bug 5419
public void EditingControlShowingTest_Unbound ()
{
using (DataGridView _dataGridView = new DataGridView ()) {
DataGridViewComboBoxColumn _nameComboBoxColumn;
DataGridViewTextBoxColumn _firstNameTextBoxColumn;
DataGridViewCheckBoxColumn _chosenCheckBoxColumn;
// Add the event-handler.
_dataGridView.EditingControlShowing
+= new DataGridViewEditingControlShowingEventHandler
(DataGridView_EditingControlShowingTest);
// No columns have been found in the event-handler yet.
editingControlShowingTest_FoundColumns = 0;
// _nameComboBoxColumn
_nameComboBoxColumn = new DataGridViewComboBoxColumn ();
_nameComboBoxColumn.HeaderText = "Name";
_dataGridView.Columns.Add (_nameComboBoxColumn);
// _firstNameTextBoxColumn
_firstNameTextBoxColumn = new DataGridViewTextBoxColumn ();
_firstNameTextBoxColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
_firstNameTextBoxColumn.HeaderText = "First Name";
_dataGridView.Columns.Add (_firstNameTextBoxColumn);
// _chosenCheckBoxColumn
_chosenCheckBoxColumn = new DataGridViewCheckBoxColumn ();
_chosenCheckBoxColumn.HeaderText = "Chosen";
_dataGridView.Columns.Add (_chosenCheckBoxColumn);
// .NET requires that all possible values for combo-boxes in a column
// are added to the column.
_nameComboBoxColumn.Items.Add ("de Icaza");
_nameComboBoxColumn.Items.Add ("Toshok");
_nameComboBoxColumn.Items.Add ("Harper");
_nameComboBoxColumn.Items.Add ("Boswell");
// Set up the contents of the data-grid.
_dataGridView.Rows.Add ("de Icaza", "Miguel", true);
_dataGridView.Rows.Add ("Toshok", "Chris", false);
_dataGridView.Rows.Add ("Harper", "Jackson", false);
_dataGridView.Rows.Add ("Boswell", "Steven", true);
// Edit a combo-box cell.
_dataGridView.CurrentCell = _dataGridView.Rows[3].Cells[0];
Assert.AreEqual (true, _dataGridView.Rows[3].Cells[0].Selected, "1-6");
Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-7");
_dataGridView.CancelEdit();
// Edit a text-box cell.
_dataGridView.CurrentCell = _dataGridView.Rows[0].Cells[1];
Assert.AreEqual (false, _dataGridView.Rows[3].Cells[0].Selected, "1-8");
Assert.AreEqual (true, _dataGridView.Rows[0].Cells[1].Selected, "1-9");
Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-10");
_dataGridView.CancelEdit();
// Edit a check-box cell.
_dataGridView.CurrentCell = _dataGridView.Rows[3].Cells[2];
Assert.AreEqual (false, _dataGridView.Rows[0].Cells[1].Selected, "1-11");
Assert.AreEqual (true, _dataGridView.Rows[3].Cells[2].Selected, "1-12");
Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-13");
_dataGridView.CancelEdit();
// Make sure the event-handler was called each time.
// (DataGridViewCheckBoxCell isn't derived from Control, so the
// EditingControlShowing event doesn't get called for it.)
Assert.AreEqual (3, editingControlShowingTest_FoundColumns, "1-14");
_dataGridView.Dispose();
}
}
示例4: AddArticleToCheque
//.........这里部分代码省略.........
else
dRow["TOT"] = GetRoundedDose(startTotal);
index = cheque.Rows.IndexOf(dRow);
rowIsUpdated = true;
}
catch (Exception ex)
{
WriteLog(ex, MethodInfo.GetCurrentMethod().Name);
}
}
//Add new row
if (!rowIsUpdated)
{
//winapi.Funcs.OutputDebugString("J");
dRow = cheque.NewRow();
dRow["ORIGPRICE"] = article["PRICE"];
//C
string c = dRow["C"].ToString();
dRow.ItemArray = article.ItemArray;
dRow["C"] = long.Parse(c);
//TAX
try
{
index = Array.IndexOf<char>(AppConfig.TAX_MarketColumn, dRow["VG"].ToString()[0]);
}
catch { index = 0; }
if (index < 0)
index = 0;
char pch = AppConfig.TAX_AppColumn[index];
index = Array.IndexOf<char>(AppConfig.TAX_AppTaxChar, pch);
if (index >= 0)
{
dRow["VG"] = pch;
dRow["TAX_VAL"] = AppConfig.TAX_AppTaxRates[index];
dRow["USEDDISC"] = AppConfig.TAX_AppTaxDisc[index];
}
if (UserConfig.Properties[17] || startTotal == 0.0)
{
Request req = new Request(dRow, startTotal);
funcRezult = req.UpdateRowSource(chqDGW);
req.Dispose();
if (!funcRezult) return;
}
else
dRow["TOT"] = startTotal;
#region Sorting article by ID and adding
if (UserConfig.Properties[14] && cheque.Rows.Count != 0)
{
index = 0;
do
{
if (GetIDCode(cheque.Rows[index]["ID"]) < GetIDCode(dRow["ID"]))
index++;
else
break;
} while (cheque.Rows.Count > index);
cheque.Rows.InsertAt(dRow, index);
}
else
{
cheque.Rows.Add(dRow);
index = cheque.Rows.Count - 1;
}
#endregion
}
//winapi.Funcs.OutputDebugString("K");
if (rowIsUpdated)
index = dRow.Table.Rows.IndexOf(dRow);
chqDGW.CurrentCell = chqDGW.Rows[index].Cells["TOT"];
try
{
object uniqueKey = article["C"];
article = (artDGW.DataSource as DataTable).Rows.Find(uniqueKey);
if (article != null)
index = (artDGW.DataSource as DataTable).Rows.IndexOf(article);
else
{
artDGW.DataSource = artsTable;
article = artsTable.Rows.Find(uniqueKey);
index = artsTable.Rows.IndexOf(article);
}
artDGW.CurrentCell = artDGW.Rows[index].Cells[artDGW.Columns.GetFirstColumn(DataGridViewElementStates.Visible).Name];
}
catch { }
chqDGW.BeginEdit(true);
if (!UserConfig.Properties[22])
chqDGW.EndEdit();
//winapi.Funcs.OutputDebugString("E");
}
示例5: ProcessDGVEditShortcutKeys
//.........这里部分代码省略.........
case "owned_date":
destRow[dc] = DateTime.Now;
break;
case "modified_by":
case "modified_date":
break;
default:
// Column is not a required field (or is a boolean field that only allows Y or N)
destRow[dc] = sourceRow[dc];
break;
}
}
}
dt.Rows.InsertAt(destRow, dgv.CurrentRow.Index + 1);
//RefreshDGVRowFormatting(dgv.Rows[dgv.CurrentRow.Index + 1], ux_checkboxHighlightChanges.Checked);
}
}
}
if (e.KeyCode == Keys.OemQuotes && e.Control)
{
if (dgv.CurrentRow != null &&
dgv.CurrentRow.Index > 0)
{
int sourceRowIndex;
DataRow sourceRow;
DataRow destinationRow;
// Processing keystroke...
keyProcessed = true;
if (dgv.CurrentRow.IsNewRow)
{
dgv.BeginEdit(true);
sourceRowIndex = dgv.CurrentRow.Index - 1;
sourceRow = ((DataRowView)dgv.Rows[sourceRowIndex].DataBoundItem).Row;
destinationRow = ((DataRowView)dgv.CurrentRow.DataBoundItem).Row;
}
else
{
sourceRowIndex = dgv.CurrentRow.Index - 1;
sourceRow = ((DataRowView)dgv.Rows[sourceRowIndex].DataBoundItem).Row;
destinationRow = ((DataRowView)dgv.CurrentRow.DataBoundItem).Row;
}
if (sourceRow != null && destinationRow != null)
{
if (!destinationRow[dgv.CurrentCell.ColumnIndex].Equals(sourceRow[dgv.CurrentCell.ColumnIndex]))
{
if (!dgv.Columns[dgv.CurrentCell.ColumnIndex].ReadOnly)
{
destinationRow[dgv.CurrentCell.ColumnIndex] = sourceRow[dgv.CurrentCell.ColumnIndex];
}
}
}
//RefreshDGVRowFormatting(dgv.CurrentCell.OwningRow, ux_checkboxHighlightChanges.Checked);
}
}
if (e.KeyCode == Keys.V && e.Control)
{
IDataObject dataObj = Clipboard.GetDataObject();
string pasteText = "";
//string[] junk = dataObj.GetFormats();
if (dataObj.GetDataPresent(System.Windows.Forms.DataFormats.UnicodeText))
{
示例6: Edit
static void Edit(DataGridView grid, string text)
{
grid.BeginEdit(false);
grid.EditingControl.Text = text;
grid.EndEdit();
}
示例7: setFocusForDataGridViewCell
private void setFocusForDataGridViewCell(DataGridView dgv, int rowindex, int cellIndex)
{
dgv.CurrentCell = dgv.Rows[rowindex].Cells[cellIndex];
dgv.CurrentCell.Selected = true;
dgv.BeginEdit(true);
}
示例8: SetCellValue
private void SetCellValue(DataGridView dataGridView, int rowIndex, int columnIndex, object value)
{
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.BeginEdit(true);
dataGridView.CurrentCell.Value = value;
dataGridView.EndEdit();
}