29 Answers, 1 is accepted
This happens because when you click a cell that is not read only as you rightly said it goes into edit mode. You are then no longer clicking on the cell you are clicking on the textbox editor so the click event is being handled there instead.
What is the goal you are trying to get to, and perhaps I can help find a suitable way around it for you.
Thanks
Richard
Even if the grid is editable, you can double click on the cell and raise the CellDoubleClick event, please take a look at the following example:
using
System;
using
System.ComponentModel;
using
System.Drawing;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
public
partial
class
Form1 : Form
{
private
RadGridView radGridView1;
private
RadTextBox radTextBox1;
public
Form1()
{
InitializeComponent();
this
.Size =
new
Size(600, 600);
this
.Controls.Add(radGridView1 =
new
RadGridView());
radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView1.Dock = DockStyle.Fill;
this
.Controls.Add(radTextBox1 =
new
RadTextBox());
radTextBox1.Dock = DockStyle.Bottom;
radTextBox1.Multiline =
true
;
radTextBox1.MinimumSize =
new
Size(0, 200);
radTextBox1.Clear();
radTextBox1.AutoScroll =
true
;
radGridView1.CellClick +=
new
GridViewCellEventHandler(radGridView1_CellClick);
radGridView1.CellDoubleClick +=
new
GridViewCellEventHandler(radGridView1_CellDoubleClick);
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
radGridView1.DataSource =
new
TestsCollection();
}
void
radGridView1_CellDoubleClick(
object
sender, GridViewCellEventArgs e)
{
radTextBox1.Text += DateTime.Now.ToString() +
": CellDoubleClick called"
+ Environment.NewLine;
}
void
radGridView1_CellClick(
object
sender, GridViewCellEventArgs e)
{
radTextBox1.Text += DateTime.Now.ToString() +
": CellClick called"
+ Environment.NewLine;
}
}
public
class
Test
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
Test(
int
id,
string
name)
{
this
.Id = id;
this
.Name = name;
}
}
public
class
TestsCollection : BindingList<Test>
{
public
TestsCollection()
{
for
(
int
i = 0; i < 10; i++)
{
this
.Add(
new
Test(i,
"Name"
+ i));
}
}
}
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
I don't beleive that this will be the case,. Can you try the following:
- Launch the program
- Double click on a cell
- the cell click event and double click event are raised and the cell is put into edit mode
- Double click on another cell, neither event is raised
- Click on a header to end edit
- The cell click is raised
- Double click on a cell, both events are raised, cell is in edit
- Double click on another cell, no events are raised
Bob, let me know your goal and I will do my best to help
Thanks
Richard
That's why i added the textbox there, so you can see exactly what happens and when.
Best Regards,
Emanuel Varga
Telerik WinForms MVP
But that's exactly my point. Bob has mentioned he would like to perform different actions on CellClick than CellDoubleClick.
Richard
Can I bind an event to the textbox editor of the cell?
Thanks for writing back. As you are using Dates in your RadgridView, I'd suggest you use a GridViewDateTimeColumn, rather than a GridViewTextBoxColumn which from your description I think you are currently using. With a GridViewDateTimeColumn you are able to set a NullValue so if any of your data does not have a Date value set then the grid will automatically set the date value to be the null value.
This will also do away with the Single Click / Double Click scenario and allow users to pick the date they wish and still pick a date from a calendar.
this link details more information on the GridViewDateTimeColumn
And here is a sample that shows the first row has an automatic date of today, even though the data for that cell is null.
Imports
Telerik.WinControls.UI
Imports
System.ComponentModel
Public
Class
Form1
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
Me
.RadGridView1.MultiSelect =
True
Me
.RadGridView1.AllowRowResize =
False
Me
.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
Me
.RadGridView1.AutoGenerateColumns =
False
Me
.RadGridView1.AllowAddNewRow =
True
Dim
nameColumn
As
New
GridViewTextBoxColumn(
"Name"
)
Dim
dateChangedColumn
As
New
GridViewDateTimeColumn(
"DateChanged"
)
dateChangedColumn.NullValue =
New
DateTime(Now.Year, Now.Month, Now.Day)
dateChangedColumn.FormatString =
"{0:dd/MM/yyyy}"
Me
.RadGridView1.Columns.Add(nameColumn)
Me
.RadGridView1.Columns.Add(dateChangedColumn)
Dim
rowInfo
As
GridViewRowInfo =
Me
.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value =
"Richard"
rowInfo.Cells(1).Value =
Nothing
' Will be set to default value (today)
rowInfo =
Me
.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value =
"Bob"
rowInfo.Cells(1).Value = Now
rowInfo =
Me
.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value =
"Ian"
rowInfo.Cells(1).Value = Now.AddDays(1)
rowInfo =
Me
.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value =
"Fred"
rowInfo.Cells(1).Value = Now.AddDays(4)
End
Sub
End
Class
hope that helps, but just let me know if you have any further questions, and I'll do my best
to help
Thanks
Richard
In that case, I will look into an alternative solution for you if you have to use a GridViewTextBoxColumn. I will get back to you as soon as possible.
All the best
Richard
I don't think this is quite right yet, and it's not the cleanest solution, but have a go with this. It does seem to work if you double click on a cell it enters the date, and single clicking on a cell puts it just into edit mode. It's just a grid on a form.
Imports
Telerik.WinControls.UI
Imports
System.ComponentModel
Public
Class
Form1
Private
WithEvents
m_BackgroundWorker
As
New
BackgroundWorker()
Private
m_DateChangedColumn
As
GridViewTextBoxColumn
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
Me
.RadGridView1.MultiSelect =
True
Me
.RadGridView1.AllowRowResize =
False
Me
.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
Me
.RadGridView1.AutoGenerateColumns =
False
Me
.RadGridView1.AllowAddNewRow =
True
Dim
nameColumn
As
New
GridViewTextBoxColumn(
"Name"
)
m_DateChangedColumn =
New
GridViewTextBoxColumn(
"DateChanged"
)
m_DateChangedColumn.FormatString =
"{0:dd/MM/yyyy}"
m_DateChangedColumn.
ReadOnly
=
True
Me
.RadGridView1.Columns.Add(nameColumn)
Me
.RadGridView1.Columns.Add(m_DateChangedColumn)
Dim
rowInfo
As
GridViewRowInfo =
Me
.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value =
"Richard"
rowInfo.Cells(1).Value =
Nothing
rowInfo =
Me
.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value =
"Bob"
rowInfo.Cells(1).Value =
Nothing
rowInfo =
Me
.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value =
"Ian"
rowInfo.Cells(1).Value = Now.AddDays(1)
rowInfo =
Me
.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value =
"Fred"
rowInfo.Cells(1).Value = Now.AddDays(4)
AddHandler
m_BackgroundWorker.RunWorkerCompleted,
AddressOf
BackgroundWorker_RunworkCompleted
End
Sub
Private
Sub
BackgroundWorker_DoWork(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.ComponentModel.DoWorkEventArgs)
Handles
m_BackgroundWorker.DoWork
Threading.Thread.Sleep(300)
End
Sub
Private
Sub
BackgroundWorker_RunworkCompleted(
ByVal
sender
As
Object
,
ByVal
e
As
RunWorkerCompletedEventArgs)
If
Me
.RadGridView1.CurrentCell.ColumnInfo.Name =
"DateChanged"
Then
m_DateChangedColumn.
ReadOnly
=
False
Me
.RadGridView1.CurrentCell.RowInfo.Cells(
"DateChanged"
).BeginEdit()
End
If
End
Sub
Private
Sub
RadGridView1_CellClick(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.GridViewCellEventArgs)
Handles
RadGridView1.CellClick
If
Me
.RadGridView1.CurrentCell.ColumnInfo.Name =
"DateChanged"
Then
m_BackgroundWorker.RunWorkerAsync()
End
If
End
Sub
Private
Sub
RadGridView1_CellDoubleClick(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.GridViewCellEventArgs)
Handles
RadGridView1.CellDoubleClick
If
Me
.RadGridView1.CurrentCell.ColumnInfo.Name =
"DateChanged"
Then
m_DateChangedColumn.
ReadOnly
=
False
If
e.Row.Cells(
"DateChanged"
).Value
Is
Nothing
Then
e.Row.Cells(
"DateChanged"
).Value = Now.ToString()
End
If
e.Row.Cells(
"DateChanged"
).BeginEdit()
End
If
End
Sub
Private
Sub
RadGridView1_CellEndEdit(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.GridViewCellEventArgs)
Handles
RadGridView1.CellEndEdit
m_DateChangedColumn.
ReadOnly
=
True
End
Sub
End
Class
Hope this helps, but let me know if you need any more information
Richard
Thanks again
Bob
All the best
Richard
My clients need to double click and open a reference form as they are editing values in a grid. So, I worked through handling CellDoubleClick when Rad GridView is not in Read Only mode by combining your examples and the one I found in this thread: RadTextBoxEditor Doubleclick not firing
To do it I add a generic double click event handler to the Cell Editor base control in the Cell Begin Edit event. The generic event calls the Cell Double Click event to mimic double clicks in Read Only mode. The code can handle Text and ComboBox columns, support for other columns was not required in my project.
My example and project uses RadControls v.2011.1.11.419
public
partial
class
Form1 : Form
{
private
RadGridView radGridView1;
private
RadTextBox radTextBox1;
bool
isTextEditorSetup;
bool
isComboBoxEditorSetup;
public
Form1()
{
InitializeComponent();
this
.Size =
new
Size(600, 600);
this
.Controls.Add(radGridView1 =
new
RadGridView());
radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView1.Dock = DockStyle.Fill;
radGridView1.ReadOnly =
false
;
this
.Controls.Add(radTextBox1 =
new
RadTextBox());
radTextBox1.Dock = DockStyle.Bottom;
radTextBox1.Multiline =
true
;
radTextBox1.MinimumSize =
new
Size(0, 200);
radTextBox1.Clear();
radTextBox1.AutoScroll =
true
;
radGridView1.CellBeginEdit +=
new
GridViewCellCancelEventHandler(radGridView1_CellBeginEdit);
radGridView1.CellDoubleClick +=
new
GridViewCellEventHandler(radGridView1_CellDoubleClick);
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
radGridView1.DataSource =
new
TestsCollection();
}
private
void
radGridView1_CellBeginEdit(
object
sender, GridViewCellCancelEventArgs e)
{
if
(!isComboBoxEditorSetup && e.Column
is
GridViewComboBoxColumn)
{
//This Event Handler applies to columns of type GridViewComboBoxColumn
((e.ActiveEditor
as
RadDropDownListEditor).EditorElement
as
RadDropDownListEditorElement).DoubleClick +=
new
EventHandler(editor_DoubleClick);
isComboBoxEditorSetup =
true
;
}
if
(!isTextEditorSetup && e.Column
is
GridViewTextBoxColumn)
{
//This Event Handler applies to columns of type GridViewTextBoxColumn
((e.ActiveEditor
as
RadTextBoxEditor).EditorElement
as
RadTextBoxEditorElement).TextBoxItem.HostedControl.DoubleClick +=
new
EventHandler(editor_DoubleClick);
isTextEditorSetup =
true
;
}
}
private
void
editor_DoubleClick(
object
sender, EventArgs e)
{
radTextBox1.Text += DateTime.Now.ToString() +
": Form1_DoubleClick called"
+ Environment.NewLine;
//Construct Arguments for CellDoubleClick
GridViewCellEventArgs arg =
new
GridViewCellEventArgs(
this
.radGridView1.CurrentRow,
this
.radGridView1.CurrentColumn,
this
.radGridView1.ActiveEditor);
radGridView1_CellDoubleClick(sender, arg);
}
private
void
radGridView1_CellDoubleClick(
object
sender, GridViewCellEventArgs e)
{
//return without doing anything if new row or one of the required double click cells is NULL.
if
(e.RowIndex == -1 || e.Row.Cells[
"Name"
].Value ==
null
|| e.Row.Cells[
"Name"
].Value == DBNull.Value)
return
;
radTextBox1.Text += DateTime.Now.ToString() +
": radGridView1_CellDoubleClick called: "
+ e.Row.Cells[
"Name"
].Value + Environment.NewLine;
}
}
public
class
Test
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
Test(
int
id,
string
name)
{
this
.Id = id;
this
.Name = name;
}
}
public
class
TestsCollection : BindingList<Test>
{
public
TestsCollection()
{
for
(
int
i = 0; i < 10; i++)
{
this
.Add(
new
Test(i,
"Name"
+ i));
}
}
}
Thank you for sharing your code and sending us the sample project. For the convenience of the customers, who will find your solution useful, I am adding a link to your the code library thread:
Cell Double Click when ReadOnly = false, for Text and ComboBox Columns
Let me know if you have any other questions.
Kind regards,Martin Vasilev
the Telerik team
Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.
How to Display record RadGridView Row Double Click and display to Rad text box?
see attached file
Let me start by mentioning that this forum concerns Telerik UI for WinForms and I will address your question for this product.
What you can do is to place RadGridView and RadDataLayout on a Form. Then you can subscribe to the CellDoubleClick event of RadGridView, and in the handler set the DataSource for RadDataLayout and it will automatically populate itself with the needed editors according to the row's fields:
Private
Sub
radGridView1_CellDoubleClick(sender
As
Object
, e
As
GridViewCellEventArgs)
dataLayout.DataSource = e.Row.DataBoundItem
End
Sub
Alternatively, instead of using the double click event, you can use CurrentRowChanged, and this way, every time the user changes the current row, the data layout control will be updated.
I hope this helps.
Regards,
Stefan
Telerik
Sir
Please send sample project
Thanks for the support
Thank you for writing back.
By default, double-clicking over a cell will activate the editor. When the editor is active and you double click on another cell, the first click will activate the editor for the new cell and the second click will be over the editor itself. Hence, you can either cancel the RadGridViewView.CellBeginEdit event or set the BeginEditMode property to RadGridViewBeginEditMode.BeginEditProgrammatically.
While working on this thread, I have encountered a rendering issue in RadDataLayout.
I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.
Currently, the possible solution that I can suggest is to use RadDataEntry instead of RadDataLayout. You can find attached a sample project.
Regards,
Dess
Telerik
Sir,
I am not using c#, I am using vb code. Pls send vb coded project...!
example is
Private Sub RadGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
RadGridView1.DoubleClick
txtID = RadGridView1.CurrentRow.Cells(0).Value
txtCustName = RadGridView1.CurrentRow.Cells(1).Value
txtAddress = RadGridView1.CurrentRow.Cells(2).Value
txtContact = RadGridView1.CurrentRow.Cells(3).Value
End Sub
Pls see attached screenshot....!
Thank you for writing back.
You can find attached a sample project in VB.NET.
Feel free to use our online code converter in future which converts from C# to VB and from VB to C#.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik
How add image row header button ?
and how to use header button?
pls attach sample in vb.net
see attached screen shot...!
Thank you for writing back.
By default, GridRowHeaderCellElements are used to indicate the current row in a RadGridView with a specific arrow image. You can use the ViewCellFormatting event and apply the desired image to the GridRowHeaderCellElement. You can find a sample demonstrating how to use the ViewCellFormatting in the following link: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik
Thank you for writing back.
You can find attached a sample project in VB.NET.
Feel free to use our online code converter in future which converts from C# to VB and from VB to C#.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik
[/quote]
the attachment file is not opening my visual studio 2010.
it gives design time error
please help me with this
[quote]Hrishikesh said:How to Display record RadGridView Row Double Click and display to Rad text box? which use code in vb.net 2010[/quote]
Have you got solution for This? if yes then please share the code.
Thanks in Advance ;-)
Thank you for writing.
I have attached a sample VS2010 project demonstrating how to handle the CellDoubleClick event and assign the cell's text to RadTextBox. The provided gif file illustrates the behavior on my end.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress
Yes, i have event CellDoubleClik on the grid, but I 2x click on the header , and open my form (stupid)
How to fix it?
Tnx a lot
this is solution
GridViewRowInfo info = this.yourGridName.CurrentRow;
if (info != null && e.RowIndex >= 0)
{
}
Thank you for writing.
I am glad that the problem you were facing is now resolved. An alternative solution for detecting whether the user clicks the header row is to check whether the GridViewCellEventArgs.Row is GridViewTableHeaderRowInfo.
Should you have further questions I would be glad to help.
Regards,
Dess
Progress Telerik