Hello,
how can i prevent to go in the edit mode if i click on a cell (not the current cell) in the current row with the mouse? i have tried to override OnMouseDownLeft:
protected override bool OnMouseDownLeft(MouseEventArgs e)
{
GridCellElement cell = this.GetCellAtPoint(e.Location);
if (cell != null)
{
GridRowElement row = this.GetRowAtPoint(e.Location);
if (row.RowInfo == this.GridControl.CurrentRow && cell != this.GridControl.CurrentCell
&& e.Clicks == 1)
{
this.GridControl.CurrentRow = null;
}
}
return base.OnMouseDownLeft(e);
}
This implementations unfortunately works with a restriction: the horizontal scrollbar jumps always completely to the left.
Regards,
Thomas
how can i prevent to go in the edit mode if i click on a cell (not the current cell) in the current row with the mouse? i have tried to override OnMouseDownLeft:
protected override bool OnMouseDownLeft(MouseEventArgs e)
{
GridCellElement cell = this.GetCellAtPoint(e.Location);
if (cell != null)
{
GridRowElement row = this.GetRowAtPoint(e.Location);
if (row.RowInfo == this.GridControl.CurrentRow && cell != this.GridControl.CurrentCell
&& e.Clicks == 1)
{
this.GridControl.CurrentRow = null;
}
}
return base.OnMouseDownLeft(e);
}
This implementations unfortunately works with a restriction: the horizontal scrollbar jumps always completely to the left.
Regards,
Thomas
10 Answers, 1 is accepted
0
Bernd Mueller
Top achievements
Rank 1
answered on 20 Jul 2010, 01:52 PM
Hello,
you could set the ReadOnly property of the grid to true to prevent editing. If you have some editable cells you can also set only a few columns editable. Here an example that makes the first column read only and the second editable:
you could set the ReadOnly property of the grid to true to prevent editing. If you have some editable cells you can also set only a few columns editable. Here an example that makes the first column read only and the second editable:
RadGridView1.MasterTemplate.Columns(0).ReadOnly = True
RadGridView1.MasterTemplate.Columns(1).ReadOnly = False
Best regards
Bernd
0
Thomas
Top achievements
Rank 1
answered on 20 Jul 2010, 01:59 PM
Hello Bernd,
I did not mean that. all cells have to be editable. but i dont want edit a cell if I clicked it only once. this happens unfortunately if you click a cell in the current row.
Best regards,
Thomas
I did not mean that. all cells have to be editable. but i dont want edit a cell if I clicked it only once. this happens unfortunately if you click a cell in the current row.
Best regards,
Thomas
0
Bernd Mueller
Top achievements
Rank 1
answered on 20 Jul 2010, 02:14 PM
Hello Thomas,
okay, now i understand the problem. Although i would consider it normal grid behaviour.
Maybe you can handle the CellBeginEdit event of the grid and set the cancel flag to true.
You just have to add some code that you don't cancel it every time.
Here: (sorry VB.NET code)
okay, now i understand the problem. Although i would consider it normal grid behaviour.
Maybe you can handle the CellBeginEdit event of the grid and set the cancel flag to true.
You just have to add some code that you don't cancel it every time.
Here: (sorry VB.NET code)
Private
Sub
GridViewBeginEdit(
ByVal
sender
As
System.
Object
,
ByVal
e
As
GridViewCellCancelEventArgs)
Handles
DataGridViewMain.CellBeginEdit
e.Cancel =
True
End
Sub
0
Thomas
Top achievements
Rank 1
answered on 20 Jul 2010, 02:17 PM
Hello Bernd,
i have tried this workarround in the past. here I constantly see the popup and hide from the editor...
Best regards,
Thomas
i have tried this workarround in the past. here I constantly see the popup and hide from the editor...
Best regards,
Thomas
0
Hello Thomas,
Thank you for starting this discussion.
I could offer you a solution which uses the custom grid behavior from your idea and the mentioned from Bernd CellBeginEdit event.
You can modify the OnMouseDownLeft in such a way that it only notifies that the cell will not go in edit mode:
The new behavior could be used in the CellBeginEdit event:
For more convenience it could be encapsulated in a custom grid control, inherited from RadGridView:
Feel free to experiment with similar solutions.
Regards,
Alexander
the Telerik team
Thank you for starting this discussion.
I could offer you a solution which uses the custom grid behavior from your idea and the mentioned from Bernd CellBeginEdit event.
You can modify the OnMouseDownLeft in such a way that it only notifies that the cell will not go in edit mode:
public
class
CustomGridBehavior : BaseGridBehavior
{
public
bool
CancelCellEdit;
protected
override
bool
OnMouseDownLeft(System.Windows.Forms.MouseEventArgs e)
{
CancelCellEdit =
false
;
GridCellElement cell =
this
.GridControl.ElementTree.GetElementAtPoint(e.Location)
as
GridCellElement;
if
(cell !=
null
)
{
GridRowElement row = cell.RowElement;
if
(row !=
null
&& row.RowInfo ==
this
.GridControl.CurrentRow &&
cell !=
this
.GridControl.CurrentCell &&
e.Clicks == 1)
{
CancelCellEdit =
true
;
}
}
return
base
.OnMouseDownLeft(e);
}
}
The new behavior could be used in the CellBeginEdit event:
this
.radGridView1.GridBehavior =
new
CustomGridBehavior();
this
.radGridView1.CellBeginEdit +=
new
GridViewCellCancelEventHandler(CustomRadGridView_CellBeginEdit);
private
void
CustomRadGridView_CellBeginEdit(
object
sender, GridViewCellCancelEventArgs e)
{
e.Cancel = ((CustomGridBehavior)
this
.radGridView1.GridBehavior).CancelCellEdit;
}
For more convenience it could be encapsulated in a custom grid control, inherited from RadGridView:
public
class
CustomRadGridView : RadGridView
{
public
override
string
ThemeClassName
{
get
{
return
typeof
(RadGridView).FullName;
}
}
public
CustomRadGridView()
{
this
.GridBehavior =
new
CustomGridBehavior();
this
.CellBeginEdit +=
new
GridViewCellCancelEventHandler(CustomRadGridView_CellBeginEdit);
}
private
void
CustomRadGridView_CellBeginEdit(
object
sender, GridViewCellCancelEventArgs e)
{
e.Cancel = ((CustomGridBehavior)
this
.GridBehavior).CancelCellEdit;
}
}
Feel free to experiment with similar solutions.
Regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Emanuel Varga
Top achievements
Rank 1
answered on 23 Jul 2010, 12:11 PM
Hello,
Or you could use an extremelly simple solution like,
Use a private member isEditing;
and
Snippet
Or you could use an extremelly simple solution like,
Use a private member isEditing;
and
Snippet
private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
if (isEditing)
{
e.Cancel = true;
}
isEditing = !isEditing;
}
0
Thomas
Top achievements
Rank 1
answered on 23 Jul 2010, 12:39 PM
The combination of both solutions works good. Thanks!
But i am wondering why this behavior is standard? why would i want to go in edit mode when i click a cell in the same row?
Regards,
Thomas
But i am wondering why this behavior is standard? why would i want to go in edit mode when i click a cell in the same row?
Regards,
Thomas
0
Emanuel Varga
Top achievements
Rank 1
answered on 23 Jul 2010, 12:44 PM
Hello Thomas,
Let's say you want to edit more than one thing at once in a grid, something maybe similar to Excel, then you would just start editing and go trough everything you need to change one by one without the need to enter editing again and again.
Glad to help,
Emanuel
Let's say you want to edit more than one thing at once in a grid, something maybe similar to Excel, then you would just start editing and go trough everything you need to change one by one without the need to enter editing again and again.
Glad to help,
Emanuel
0
Thomas
Top achievements
Rank 1
answered on 23 Jul 2010, 12:46 PM
I would unterstand this, if the first selected cell is already in edit mode! but this is not necessary in the standard behavior!
Regards,
Thomas
Regards,
Thomas
0
Hello Thomas,
The standard behavior of RadGridView is defined by our UI experts when the first version of the control has been under development.
Thank you for your suggestion for the new behavior. It is fine and we will consider that for the future development of the control. We could either make it default or provide suitable API for choosing it.
We are eager and thankful to hear all your ideas for improvements regarding our products.
Best regards,
Alexander
the Telerik team
The standard behavior of RadGridView is defined by our UI experts when the first version of the control has been under development.
Thank you for your suggestion for the new behavior. It is fine and we will consider that for the future development of the control. We could either make it default or provide suitable API for choosing it.
We are eager and thankful to hear all your ideas for improvements regarding our products.
Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items