Here is the code I am using:
It does not work under these circumstances:
1) The second time the code is called.
I have the code in an Add button, so when the user clicks Add to add a new row, the 3rd cell is automatically opened for edit. This works the first time I click the Add button. But if I press it a second time, it does not work. I tried to call EndEdit before this code, and that did not help.
2) If the cell is a drop down list.
If the cell to automatically open for edit is a drop down list, the code does not work. It does not show the comboBox editor.
Any tips for fixing either of these issues is appreciated!
17 Answers, 1 is accepted
Please try something like this: (if you have any problems please uncomment those lines, the first one should be in the case of multiselection to prevent multiple cells from being selected, and the second one is because the grids virtualization mechanism to force all pending async operations to be performed)
Hope this helps, if you have any other questions or comments, please let me know,
Looks like Emanuel has addressed the drop down here. I've just tried this. Almost the same as your code...
and from the button click it always works the second time around too. Perhaps in your case the endEdit is not being called correctly. You can always call EndEdit() before begin edit to see if that's the case.
Hope that helps also.
//Off Topic - Emanuel - congratulations on your MVP status. Totally deserved. - Richard
You don't need these lines:
What I've posted earlier is working by itself, because you when you say BeginEdit() you are starting an edit operation on the CurrentCell, not on the selected row, and not on the selected column....
It's true, but I put them in to replicate what Deborah had done.
When I break on the If statement, the ActiveEditor is nothing. I am also NOT getting a CellBeginEdit event after executing the BeginEdit statement.
As I mentioned earlier, this is in an Add button click event. Is it possible that yours works and mine does not because I am adding the row to the underlying datasource in the same method?
Here is the entire click event:
Any other ideas?
The code i've posted earlier is fired from a button click, please take a look at this example and tell me if this is working for you, and then we'll continue from there:
I think that the issue comes from trying to add a new row and also begin edit at the same time. I was able to replicate your issue of not being able to edit on the second time. I managed to solve this by calling BeginUpdate and endUpdate on the RadGridView.
See the example below.
Taking away the lines..
shows that you can no longer perform the operation twice.
Let me know if that helps
Note from my original post that the code I posted *does* work when I click the Add button if the column is a Textbox AND it is the first time that I click. It just does not work a second time. Nor does it work with a combobox. NOTE: I am using a Combox and not a DropDownList because DropDownlist is not a choice in the designer and this grid was created with the designer. Could that be the problem?
I wondered if I need to somehow end the prior edit?
Or if I need to use a different event because the new row was not finished generating when I just added it to the underlying list?
Have you tried the BeginUpdate() and EndUpdate() as I suggested?
Thank you! Thank you! Thank you!
I posted my prior message before I received your reply. Using BeginUpdate and EndUpdate worked. I had tried it before, but not around the code I was using to add the row.
For anyone else with this problem note that this ALSO fixed the problem with the combobox.
Just one more question if I may ... what is BeginUpdate and EndUpdate doing exactly?
Glad that this has worked for you. Please remember to mark as answer so others can find the solution too.
BeginUpdate prepares the grid for certain operations to take place and is also used to enhance performance.
This seems to be one of the few WinForms threads on the topic of activating the drop down by just clicking once into a cell. I've modified the accepted answer a bit to fire during the cell's click event. The accepted answer works but actually then causes all other columns to activate the edit mode upon a cell's click. I also shortened the lines of code up using C#'s new null propagation operator.
Thank you for sharing your solution.
Indeed, this is a valid approach for opening up the drop down.
Please let me know if you need additional assistance.
How to make this happen when i called it from another form
Dim currentCell As GridViewCellInfo = RadGridView1.Rows(RadGridView1.Rows.Count - 1).Cells(1)
currentCell.IsSelected = True
This the code i wrote for fill raggridview form another form, i need to edit mode cell 2.
Dim frm = Application.OpenForms("FrmBeli")
If frm IsNot Nothing Then
If GridCari.CurrentRow.Index <> -1 Then
i = GridCari.CurrentRow.Index
CType(frm, FrmBeli).GridDetail.Rows.Add(GridCari.Rows(i).Cells(0).Value.ToString(), GridCari.Rows(i).Cells(1).Value.ToString())
Thank you for writing.
As long as you can access the form with the grid from the other form you should not have issues with setting a particular cell in EditMode. For example, you can expose a public method in the grid form and pass as parameters the row and column indices of the cell you want to select. Then you can call the RadGridView.BeginEdit method.
In case you need further assistance please provide me with more details about your actual scenario.
I hope this helps. Let me know if you need further assistance.