473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DataGrid Edit field

(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
Jun 24 '06 #1
4 7609
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

Jun 24 '06 #2

"Ian Semmel" <is***********@NOKUNKrocketcomp.com.au> wrote in message
news:ev**************@TK2MSFTNGP04.phx.gbl...
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
Jun 25 '06 #3

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> wrote in message
news:Me**************@TK2MSFTNGXA01.phx.gbl...
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!
Jun 26 '06 #4
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.

Jun 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stan | last post by:
This is how I access Pieces field in my editable datargid during Update event: protected void grdMain_OnUpdate(Object sender, DataGridCommandEventArgs e) { string Pieces = ((TextBox)...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Colin Ramsay | last post by:
Hi all, I don't normally post swathes of code like this but I am truly banging my head off my desk here... I've dynamically created a datagrid within a usercontrol. There are two columns...
2
by: CW | last post by:
In an earlier thread, I was asking for help on "Invalid attempt to FieldCount when reader is closed" error when I was using a dataset rather than a datareader to bind to a datagrid. After...
12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
1
by: Harry Devine | last post by:
I have a DataGrid that is configured to use the Edit/Update/Cancel concept correctly. My grid shows values from 5 database fields. I only need to update that last 4 fields. The last field is a...
5
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.