CType(e.CurrentRow, GridViewNewRowInfo).Cells("Acct_Code").CellElement.Focus()
but it has no effect. I looked into some of the other events, RowChanging and DefaultValuesNeeded, but CellElement is nothing at that point.
9 Answers, 1 is accepted
I am not sure that I completely understand your question. You can change the current column by settingGridViewColumn.IsCurrent property. For example:
Me
.radGridView1.Columns(
"Acct_Code"
).IsCurrent =
True
Then you can start editing a cell by calling RadGridView.BeginEdit method. If this doesn't help, please describe in more detail the exact behavior that you want to achieve. I will be glad to help further.
Regards,
Jackthe 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.
CType(e.CurrentRow, GridViewNewRowInfo).Cells("Acct_Code").CellElement.Enabled = True |
Me.TblAccountRadGridView.Columns("Acct_Code").IsCurrent = True |
Me.TblAccountRadGridView.BeginEdit() |
Thank you for writing back. This code should do the work, however it should be called when RadGridView is visible. You can call it in OnShown method of your form. Consider the code snippet below:
protected
override
void
OnShown(EventArgs e)
{
base
.OnShown(e);
this
.radGridView1.BeginEdit();
}
Please send me your project if this doesn't help. I will try to find a working solution.
Greetings,
Jackthe 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.
Thank you for this clarification. If I understand your question correctly, you want to make the first column current and editable when clicking on "add new row". Here is the code in VB:
Me
.RadGridView1.GridBehavior =
New
MyGridBehavior()
Public
Class
MyGridBehavior
Inherits
BaseGridBehavior
Public
Overrides
Function
OnMouseDown(
ByVal
e
As
System.Windows.Forms.MouseEventArgs)
As
Boolean
Dim
element
As
GridRowElement = TryCast(GridControl.ElementTree.GetElementAtPoint(e.Location), GridRowElement)
If
element IsNot
Nothing
Then
GridControl.Columns(0).IsCurrent =
True
GridControl.MasterGridViewInfo.TableAddNewRow.IsCurrent =
True
GridControl.BeginEdit()
Return
True
End
If
Return
MyBase
.OnMouseDown(e)
End
Function
End
Class
I hope this helps.
Kind regards,
Jackthe 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.
This does not work when another row is currently being edited. Steps:
1. Click to edit a cell in another row, such that it shows a textbox for editing.
2. Click the Add New row.
What happens is that the same column that was being edited is the column that will start the New Row edits, not the first column. Setting IsCurrent appears to be getting ignored.
Thank you for writing.
The code snippet my colleague has posted will no longer compile as the grid does not have a MasterGridViewInfo property. I am posting an updated version below:
public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
this
.radGridView1.GridBehavior =
new
MyGridBehavior();
this
.radGridView1.DataSource =
this
.GetData();
this
.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
private
DataTable GetData()
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(
int
));
dt.Columns.Add(
"Name"
,
typeof
(
string
));
dt.Columns.Add(
"Date"
,
typeof
(DateTime));
dt.Columns.Add(
"Bool"
,
typeof
(
bool
));
for
(
int
i = 0; i < 10; i++)
{
dt.Rows.Add(i,
"Name "
+ i, DateTime.Now.AddDays(i), i % 2 == 0);
}
return
dt;
}
}
public
class
MyGridBehavior : BaseGridBehavior
{
public
override
bool
OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
GridRowElement element =
this
.GridControl.ElementTree.GetElementAtPoint(e.Location)
as
GridRowElement;
if
(element !=
null
)
{
this
.GridControl.Columns[0].IsCurrent =
true
;
this
.GridControl.MasterView.TableAddNewRow.IsCurrent =
true
;
this
.GridControl.BeginEdit();
return
true
;
}
return
base
.OnMouseDown(e);
}
}
Please also check the attached short video showing the result on my end. With the provided solution the grid begins edit in the first column no matter if another is being edited at the moment or not.
In case your scenario is different or the solution is not working as expected on your end, please provide me with more details about your scenario so that I can investigate it. A sample code snippet could also help. In case you want to send us your project you can do it using the ticketing system.
I hope this helps. Let me know if you need further assistance.
Regards,
Hristo
Progress Telerik
Found it. Has to do with the first column in my grid not being visible (because it was the "Id" column), so that when the GridBehavior attempts to make it current, the grid ignores the IsCurrent setting entirely, so that the current column isn't changed.
Better code for MyGridBehavior:
public
class
MyGridBehavior : BaseGridBehavior
{
public
override
bool
OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
GridRowElement element =
this
.GridControl.ElementTree.GetElementAtPoint(e.Location)
as
GridRowElement;
if
(element !=
null
)
{
for
(
int
i = 0; i <
this
.GridControl.Columns.Count; i++)
{
if
(
this
.GridControl.Columns[i].IsVisible)
{
this
.GridControl.Columns[i].IsCurrent =
true
;
break
;
}
}
this
.GridControl.MasterView.TableAddNewRow.IsCurrent =
true
;
this
.GridControl.BeginEdit();
return
true
;
}
return
base
.OnMouseDown(e);
}
}
Thank you for the update.
Indeed the code snippet you shared seems valid and as long as it handles your actual scenario you can go ahead with it.
Let me know if you have other questions.
Regards,
Hristo
Progress Telerik