DataGridView.EndEdit Question

R

Rainer Queck

Hello NG,

It seems, that "DataGridView.EndEdit()" does not work here.
There a two reasons, why I think this:
1. After DataGridView.EndEdit() the currently selected row still shows the
pencil, indication that it is in edit mode
2. With in my program I realize, that the changes made in the dgv are not
"known" in the code, using the underlaying data table, although dgv.EndEdit
was called,
before I used the datatable.

Is there something else I have to do, in order to make sure that editing has
ended befor accesing the related datatables?

Thanks for help!
Rainer Queck
 
J

Jeffrey Tan[MSFT]

Hi Rainer,

Can you provide the sample code to demonstrating this behavior? I have
created a sample project to test DataGridView.EndEdit() method. Below is
the sample code:

DataTable dt;
private void Form1_Load(object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("column1", typeof(int)));
dt.Columns.Add(new DataColumn("column2", typeof(string)));

for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i;
dr["column2"] = "item" + i.ToString();
dt.Rows.Add(dr);
}
this.dataGridView1.DataSource = dt;
}

private void timer1_Tick(object sender, EventArgs e)
{
this.dataGridView1.EndEdit();
Console.WriteLine(this.dt.Rows[0]["column2"].ToString());
}

As you can see, I use a winform timer to call the DataGridView.EndEdit()
method every few seconds. Also, in the timer, I printed out the
Rows[0]["column2"] cell content in debugger's "Output" window. In the
testing, I find that the DataGridView.EndEdit() will take effect. The
"pecil" will disappear with the DataGridView.EndEdit() calling, also the
underlying DataTable cell content will change.

I will wait for your reproduce sample project, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rainer Queck

Good Morning Jeffrey,

thanks for helping me.

The method, where I modiy fy my datagridview and then do the EndEdit looks
like this:

private void deselectUseCaplayoutToolStripMenuItem_Click(object sender,
EventArgs e)
{
foreach (DataGridViewRow r in dgvCombine.Rows)
{
r.Cells["useCombineDataGridViewCheckBoxColumn"].Value = false;
}
dgvCombine.EndEdit();
}

This method is called by a click on a context menue, hookt up with the
datagridview.
The pencil stays activ. I could send you a snapshot of how it looks.

Regards
Rainer Queck

"Jeffrey Tan[MSFT]" said:
Hi Rainer,

Can you provide the sample code to demonstrating this behavior? I have
created a sample project to test DataGridView.EndEdit() method. Below is
the sample code:

DataTable dt;
private void Form1_Load(object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("column1", typeof(int)));
dt.Columns.Add(new DataColumn("column2", typeof(string)));

for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i;
dr["column2"] = "item" + i.ToString();
dt.Rows.Add(dr);
}
this.dataGridView1.DataSource = dt;
}

private void timer1_Tick(object sender, EventArgs e)
{
this.dataGridView1.EndEdit();
Console.WriteLine(this.dt.Rows[0]["column2"].ToString());
}

As you can see, I use a winform timer to call the DataGridView.EndEdit()
method every few seconds. Also, in the timer, I printed out the
Rows[0]["column2"] cell content in debugger's "Output" window. In the
testing, I find that the DataGridView.EndEdit() will take effect. The
"pecil" will disappear with the DataGridView.EndEdit() calling, also the
underlying DataTable cell content will change.

I will wait for your reproduce sample project, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
R

Rainer Queck

Hello Jeffry,

thanks again for trying to help me.
I tried your sample, and it works fine here too.

I looked a little deeper into this project, an found something that could be
related to the problem.
In our datagridview, we are handling the "CellValueNeeded" event, because
there are some celles that need extra calculation.
Therefore we also have set the VirtualMode Property to true.

Could that have something to do wich my problem?

Regards
Rainer Queck
 
R

Rainer Queck

Hello Jeffrey,

I am happy to be able to present a demo project, that exactly shows my
issue. I sent the demo to you seperately, hoping that it reaches you. Please
let me know if it did!

Here are the steps to do to reproduce the issue:
- deselect one of the checkboxes and thereby bring the dgv into edit mode
- click on Button "Clear All Bool"
now you see that all the bools are cleared, but the previously selected row
still is in Edit mode even though I at the ende of the "btnBool_Click" do a
EndEdit().
also from now on you can click the button "EndEdit" es often as you want,
and still don't leave the edit mode.
This situation can now only bee ended by selecting a differen row.

So, what is it I am doing wrong?
Looking forward to you help soon. I am on a customers site and have to solve
my problem!

Regards
Rainer Queck
 
G

Greg Wright

I had the same problem and found that if I set Virtual = false, then the glyph went away after doing the EndEdit() function. I didn't have to do an EndEdit at all after that to get the Pencil gliph to disappear. Hope that helps.

Greg
SnapJag.com
gleew.wordpress.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top