Results 1 to 7 of 7

Thread: On WPF DataGrid, how to programmatically put a cell into edit mode?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Question 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?

  2. #2
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    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.

  6. #6
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: On WPF DataGrid, how to programmatically put a cell into edit mode?


    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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
  •  



Click Here to Expand Forum to Full Width