-
Sep 1st, 2015, 11:57 AM
#1
Thread Starter
Hyperactive Member
On WPF DataGrid, how to programmatically put a cell into edit mode?
Okay, I have a WPF DataGrid which is bound to an Observable Collection of data objects. It's a 2-way binding. I have an "Add" button that adds a data row to the underlying list, scrolls to that item in the DataGrid, and selects that row. All that works perfectly. The UI shows an empty row added to the end of the DataGrid, and that row is selected. However, the user has to click the first cell in order to edit it, which isn't ideal.
Once I've gotten this far, how do I tell it to open the first cell into edit mode? I tried the obvious, dataGrid.BeginEdit(), but it didn't do anything that I can see. Still have to click the cell to put it in edit mode. I also tried some solutions culled from online, using the visual tree to select a cell, but that didn't work, either... the cell always came back null.
I have the DataGrid.SelectionUnit set to FullRow, and the SelectionMode set to Extended. I cannot set the SelectionUnit to Cell, because there are several scenarios the user will want to select multiple rows.
So, any idea how to set a column to edit mode from the code-behind?
-
Sep 1st, 2015, 03:42 PM
#2
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Try something like this: (adapt to your own controls).
Code:
PlantasDataGridView.Rows(0).Cells(1).Selected = True
PlantasDataGridView.Focus()
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Sep 1st, 2015, 03:50 PM
#3
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Sorry, typed that last example without testing it. This one works:
Code:
PlantasDataGridView.CurrentCell = PlantasDataGridView.Rows(0).Cells(1)
PlantasDataGridView.Focus()
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Sep 1st, 2015, 10:21 PM
#4
Thread Starter
Hyperactive Member
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Hmmm... that looks like it's for a DataGridView control. I'm using a DataGrid control. I do not believe this code will work on a DataGrid, but I'll try it first thing in the morning.
-
Sep 2nd, 2015, 02:05 PM
#5
Thread Starter
Hyperactive Member
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Confirmed. This is a solution that might work with DataGridView but not with DataGrid.
-
Sep 2nd, 2015, 02:45 PM
#6
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Yeah, sorry. Did not pay close attention to that.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Sep 2nd, 2015, 05:24 PM
#7
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|