PC Review


Reply
Thread Tools Rate Thread

DataGrid Edit field

 
 
Peter
Guest
Posts: n/a
 
      24th Jun 2006
(VS 2003)

I have a DataGrid and accept button. My problem is when a user starts to
edit one of the values in the grid and does not either press Enter or move
of the current cell and presses the Accept buton the current typed value
does not get passed into the grid, but stays in the edit mode. How can I
move the current edit value into the grid without requireing user to press
Enter or move to a different cell?

Thanks



Peter


 
Reply With Quote
 
 
 
 
Ian Semmel
Guest
Posts: n/a
 
      24th Jun 2006
What I do (which may not be the best way) is programmatically set CurrentCell to
a different value (if possible)

public void AdjustDataGridView ( DataGridView dgv )
{
DataGridViewRow currentRow = dgv.CurrentRow;
DataGridViewCell currentCell = dgv.CurrentCell;
if ( currentCell != null )
{
int rowIndex = currentCell.RowIndex + 1;
int columnIndex = currentCell.ColumnIndex;
if ( rowIndex >= dgv.Rows.Count )
rowIndex = 0;
dgv.CurrentCell = dgv.Rows [ rowIndex ].Cells [ columnIndex ];
}
}




Peter wrote:
> (VS 2003)
>
> I have a DataGrid and accept button. My problem is when a user starts to
> edit one of the values in the grid and does not either press Enter or move
> of the current cell and presses the Accept buton the current typed value
> does not get passed into the grid, but stays in the edit mode. How can I
> move the current edit value into the grid without requireing user to press
> Enter or move to a different cell?
>
> Thanks
>
>
>
> Peter
>
>

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      25th Jun 2006

"Ian Semmel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What I do (which may not be the best way) is programmatically set
> CurrentCell to a different value (if possible)
>
> public void AdjustDataGridView ( DataGridView dgv )
> {
> DataGridViewRow currentRow = dgv.CurrentRow;
> DataGridViewCell currentCell = dgv.CurrentCell;
> if ( currentCell != null )
> {
> int rowIndex = currentCell.RowIndex + 1;
> int columnIndex = currentCell.ColumnIndex;
> if ( rowIndex >= dgv.Rows.Count )
> rowIndex = 0;
> dgv.CurrentCell = dgv.Rows [ rowIndex ].Cells [ columnIndex ];
> }
> }
>
>
>
>
> Peter wrote:
>> (VS 2003)
>>
>> I have a DataGrid and accept button. My problem is when a user starts to
>> edit one of the values in the grid and does not either press Enter or
>> move of the current cell and presses the Accept buton the current typed
>> value does not get passed into the grid, but stays in the edit mode. How
>> can I move the current edit value into the grid without requireing user
>> to press Enter or move to a different cell?
>>
>> Thanks
>>
>>
>>
>> Peter


Thanks for your help

But I am using VS 2003 and DataGrid not DataGridView, so changing row index
removes the value you just typed


 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      26th Jun 2006

""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Peter,
>
> Thanks for your post!
>
> I assume you want to end the current editing mode and push the modifying
> data into the datasource without changing the current cell and changing
> the
> focus to other controls. If I misunderstand you, please feel free to tell
> me, thanks.
>
> First, based on my test, Ian Semmel's suggestion of changing the current
> cell programmatically will push the current modifying data into the
> datasource without any problem.
> //I use a timer to end the current edit
> //for simplicity, I did not take last row into account.
> private void timer1_Tick(object sender, System.EventArgs e)
> {
> DataGridCell dgc=this.dataGrid1.CurrentCell;
> this.dataGrid1.CurrentCell=new DataGridCell(dgc.RowNumber+1,
> dgc.ColumnNumber);
> }
> This works well on my test project. Do you have any problem get this
> working?
>
> Second, if you are creating the column styles yourself without using the
> auto generated column styles in DataGrid, you can use dataGrid.EndEdit
> method to get what you want, like this:
>
> private void timer1_Tick(object sender, System.EventArgs e)
> {
> this.dataGrid1.EndEdit(this.dataGridTextBoxColumn1,
> this.dataGrid1.CurrentCell.RowNumber, false);
> this.dataGrid1.EndEdit(this.dataGridTextBoxColumn2,
> this.dataGrid1.CurrentCell.RowNumber, false);
> }
> I have attached my sample project in this reply for your reference. This
> sample project end the editing in 5 seconds, and it will display the
> "column2"'s first cell value, so you may modify this cell value in
> DataGrid
> and wait for the display at runtime.(Note: run it in debug mode and see
> the
> Console.WriteLine output in "Output" window in VS.net2003 IDE)
>
> Finally, can you tell me where you want to place the code to end the edit
> mode? If you want to end the edit from another non-UI thread, the code
> needs to be marshaled with Control.Invoke/BeginInvoke method calling,
> because the .Net Winform uses STA threading model, which means any
> manipulation to the GUI thread needs to be marshaled.
>
> Hope this helps!
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Community Support
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.



Thank you very much!

This works great!


 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      27th Jun 2006
You are welcome.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit All Function for DataGrid, and Moving the Edit Function in a DataGrid Schultz Microsoft ASP .NET 3 14th Feb 2005 04:47 AM
Edit in DataGrid =?Utf-8?B?cmtibmFpcg==?= Microsoft ASP .NET 1 25th Jan 2005 08:05 PM
dynamically calc edit field in datagrid hansiman Microsoft ASP .NET 1 13th Dec 2004 03:50 PM
datagrid-edit mode by selecting (or double clicking field) tshad Microsoft ASP .NET 1 29th Oct 2004 05:20 AM
Edit in DataGrid DC Microsoft ASP .NET 4 26th Dec 2003 09:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:01 AM.