I've set RegexpPattern property in Infragistics UltraWinGrid column and it works - when user edit cell and given input doesn't match regexp cell is cleared. I would like to restore previous ( before edit started) value of cell instead of make it blank. How can I do it?
thanks in advance!
I found solution:
Create event handler for grid's event: CellDataError - set event argument properties as in following sample:
private void _ultraGrid_ConfigList_CellDataError(object sender, Infragistics.Win.UltraWinGrid.CellDataErrorEventArgs e)
{
e.StayInEditMode = false;
e.RaiseErrorEvent = false;
e.RestoreOriginalValue = true;
}
Related
Can't find any way to do what i what.
I have a DataGridView named data1. All i want is to check if current cell is acceptable(not lower than -99) after we fill it. And if it is - change it to -99. Similar if i set minimum to a textbox and change its value if it's not correct.
Here is the code:
private void data1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (Convert.ToInt32(((DataGridView)sender).CurrentCell.Value) < -99)
{
((DataGridView)sender).CurrentCell.Value = -99;
}
}
This code does not work. And no errors appeared.
This code works as you want it to:
private void data1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
DataGridViewTextBoxCell cell = (DataGridViewTextBoxCell)data1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (Convert.ToInt32(cell.Value) <= -99)
cell.Value = -99;
}
Cellleave Event gets previous value of the cell after you have changed it to a different one and left the cell. And CellEndEdit Event gets the last value. The code works the same also in CellValidated Event.
I think what you are looking for is DataGridView.CellValidating this event fires when the user is leaving the current cell but before CellLeave fires or bound data gets pushed to the datasource. This allows you to: check the value the user entered, prevent the user from leaving the cell, change the value the user entered, set an error indicator on the cell.
I have created an unbound column which I intend to populate with calculated data; however, I am unable to get the CustomUnboundColumnData event to fire. I basically copied the code from DevExpress documentation on https://documentation.devexpress.com/#WindowsForms/CustomDocument1477
As per other posts found I made sure that there are no other columns with the same name.
The new unbound column does indeed appear in the grid, but the event is never firing so I don't know how to populate it.
In my constructor I define the columns as below: (I made sure there are no other columns with the same name)
GridColumn testColumn = new GridColumn();
testColumn.FieldName = "Test Column1";
testColumn.VisibleIndex = gridView1.Columns.Count;
testColumn.UnboundType = DevExpress.Data.UnboundColumnType.DateTime;
// Disable editing.
testColumn.OptionsColumn.AllowEdit = true;
// Specify format settings.
testColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
testColumn.DisplayFormat.FormatString = "d";
testColumn.Visible = true;
gridView1.Columns.Add(testColumn);
Then I have my event function which never fires
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{
MessageBox.Show("unbound column a go go");
How can I populate the unbound column?
Solved thanks to DevExpress support forum (which is very nice by the way)
I was missing the line for gridView1.CustomUnboundColumnData += gridView1_CustomUnboundColumnData; which tells the grid which event handler(s) to use for unbound columns
In winforms, you need to click the combobox twice to properly activate it - the first time to focus it, the second time to actually get the dropdown list.
How do I change this behavior so that it activates on the very first click?
This is for DATAGRIDVIEW combobox.
I realize this is an old question, but I figured I would give my solution to anyone out there that may need to be able to do this.
While I couldn't find any answers to do exactly this... I did find an answer to a different question that helped me.
This is my solution:
private void datagridview_CellEnter(object sender, DataGridViewCellEventArgs e)
{
bool validClick = (e.RowIndex != -1 && e.ColumnIndex != -1); //Make sure the clicked row/column is valid.
var datagridview = sender as DataGridView;
// Check to make sure the cell clicked is the cell containing the combobox
if(datagridview.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn && validClick)
{
datagridview.BeginEdit(true);
((ComboBox)datagridview.EditingControl).DroppedDown = true;
}
}
private void datagridview_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
datagridview.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
The above code must be tied into the CellEnter event of the datagridview.
I hope this helps!
edit: Added a column index check to prevent crashing when the entire row is selected.
Thanks, Up All Night for the above edit
edit2: Code is now to be tied to the CellEnter rather than the CellClick event.
Thanks, HaraldDutch for the above edit
edit3: Any changes will committed immediately, this will save you from clicking in another cell in order to update the current combobox cell.
Set the following on your DataGridView:
EditMode = EditOnEnter
This is probably the easiest solution and has been the workaround for many users here on SO when this question gets asked.
EDIT :
Per here do the following:
Set the Editmode:
EditMode = EditOnKeystrokeOrF2
Modify the EditingControlShowing event on the datagridview:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox ctl = e.Control as ComboBox;
ctl.Enter -= new EventHandler(ctl_Enter);
ctl.Enter += new EventHandler(ctl_Enter);
}
void ctl_Enter(object sender, EventArgs e)
{
(sender as ComboBox).DroppedDown = true;
}
This will get you your desired results. Let me know if that doesn't do it.
I changed only the EditMode property of the datagridview to EditOnEnter and it's working perfectly.
EditMode = EditOnEnter
If you set the entire grid to EditOnEnter, you can get some pretty funky activity when you are on a text column. Here's my solution, which should be self explanatory. If you did not know the column names, you could just check the cell type on mousemove.
Private Sub GridView_CellMouseMove(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles GridView.CellMouseMove
Select Case GridView.Columns(e.ColumnIndex).Name
Case "Ad_Edit", "Size_Caption", "Demo_Code"
GridView.EditMode = DataGridViewEditMode.EditOnEnter
Case Else
GridView.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2
End Select
End Sub
Set the DropDownStyle property of your combo box to DropDownList...
Perhaps old.. But make sure to set ReadOnly property to false, else the cell wont enter editmode and therefore the EditingControl returns null and casting DroppedDown = true will cast a NullReferencException.
I'm trying to disable editing for specific gridview cells.
I'm using a RepositoryItemTextEdit with the following properites:
repositoryItemTextEdit.AllowFocused = false;
m_repositoryItemTextEdit.ReadOnly = true;
However i can still click the cell and the edit cursor is present even if i can't change the value.
Is there a way o get rid of the text cursor?
Thank you
I got a same problem the cell and the edit cursor is present while after disabled.
And i got the solution.
private void tree_ShowingEditor(object sender, CancelEventArgs e)
{
Nodes.PromptNode promptNode = tree.FocusedNode as Nodes.PromptNode;
if (tree.FocusedColumn == valueColumn && promptNode.PromptResult.ValueType.MyValueType == ValueType.ValueTypeOptions.Calculated)
{
e.Cancel = true;
}
}
Using ShowingEditor event to cancelled this.
Basically, you have to handle the ShownEditor Event of the GridView. In there, you test the focused row and column and if the cell should be readonly, you do:
grdView.ActiveEditor.Properties.ReadOnly = True
To make things nice and understanable for the user, you can also handle the CustomDrawCell Event, and set the background color (e.Appearance) to the color used for your readonly controls.
This might be somewhat besides the point, since it doesn't get rid of the cursor; but I don't see what that would be useful.
i have a datagridview and i would like the rowheader to correctly select that entire row.
Although i thought it should anyway, it does not. i have tried the following but with no luck, can you see something obvious? =P
regards, Dave
private void dataGridView2_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
dataGridView2.Rows[e.RowIndex].Selected = true;
}
Try setting the
DataGridView.MultiSelect=false;
and
DataGridView.SelectionMode = FullRowSelect;
You can read about the MultiSelect Property and SelectionMode Property in the MSDN library linked.
If you want the user to select multiple rows, then set MultiSelect to true.
DataGridView.MultiSelect=true;
EDIT
And then you can call your event like this:
private void dataGridView2_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
dataGridView2.Rows[e.RowIndex].Selected = true;
}
To select individual cells within the data grid view and select the entire row on row header click, set the selection mode to RowHeaderSelect
DataGridView.SelectionMode = RowHeaderSelect;
The MSDN explanation for RowHeaderSelect is: Clicking a cell selects it. Clicking a row header selects the entire row.