DGV doesn't update value

Multi tool use
I Inerted a DGV called MarksDGV1
into my application while each cell inside of it has a default value of "0". So, after the user changes the value of some of them, when I try to reach the value for the last edited cell it gives me 0 instead of what the user typed even though it's shown correctly
(Please note: the unselected cells -which doesn't appear in Blue color- show value correctly)
How could I fix that?
Here is my code:
MarksDGV1.Refresh();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
And this is How I built the DGV:
using (DataGridViewTextBoxColumn tmp = new DataGridViewTextBoxColumn())
{
tmp.Width = 90;
tmp.ReadOnly = true;
tmp.HeaderText = "פרק מס.";
MarksDGV1.Columns.Add(tmp);
}
for (int i = 1; i <= 30; i++)
{
using (DataGridViewTextBoxColumn tmp = new DataGridViewTextBoxColumn())
{
tmp.Width = 50;
tmp.HeaderText = "שאלה מס." + i;
MarksDGV1.Columns.Add(tmp);
}
}
for (int i = 0; i < 8; i++)
{
using (DataGridViewRow tmp = (DataGridViewRow)MarksDGV1.Rows[i].Clone())
{
tmp.Cells[0].Value = i + 1;
for (int j = 1; j <= 30; j++)
{
tmp.Cells[j].Value = 0;
//tmp.Cells[j].Value = CurrentExam.Psy[i].Answers[j - 1];
}
MarksDGV1.Rows.Add(tmp);
}
}
Update: I tried typing DataGridView.Refresh();
but didn't work!
Update2: I was able to fix this by selecting another cell -different from the one that I'm concerned in- before I get the values. But that's not a solution for me
c# datagridview
New contributor
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 11 more comments
I Inerted a DGV called MarksDGV1
into my application while each cell inside of it has a default value of "0". So, after the user changes the value of some of them, when I try to reach the value for the last edited cell it gives me 0 instead of what the user typed even though it's shown correctly
(Please note: the unselected cells -which doesn't appear in Blue color- show value correctly)
How could I fix that?
Here is my code:
MarksDGV1.Refresh();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
And this is How I built the DGV:
using (DataGridViewTextBoxColumn tmp = new DataGridViewTextBoxColumn())
{
tmp.Width = 90;
tmp.ReadOnly = true;
tmp.HeaderText = "פרק מס.";
MarksDGV1.Columns.Add(tmp);
}
for (int i = 1; i <= 30; i++)
{
using (DataGridViewTextBoxColumn tmp = new DataGridViewTextBoxColumn())
{
tmp.Width = 50;
tmp.HeaderText = "שאלה מס." + i;
MarksDGV1.Columns.Add(tmp);
}
}
for (int i = 0; i < 8; i++)
{
using (DataGridViewRow tmp = (DataGridViewRow)MarksDGV1.Rows[i].Clone())
{
tmp.Cells[0].Value = i + 1;
for (int j = 1; j <= 30; j++)
{
tmp.Cells[j].Value = 0;
//tmp.Cells[j].Value = CurrentExam.Psy[i].Answers[j - 1];
}
MarksDGV1.Rows.Add(tmp);
}
}
Update: I tried typing DataGridView.Refresh();
but didn't work!
Update2: I was able to fix this by selecting another cell -different from the one that I'm concerned in- before I get the values. But that's not a solution for me
c# datagridview
New contributor
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Try setting the DataSource to null : datagridview1.DataSource = null; datagridview1.DataSource = dt (or what ever the source actually is)
– jdweng
Dec 27 '18 at 15:22
@RezaAghaei I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@krobelusmeetsyndra I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@jdweng I didn't use a data source to build my DGV
– Ahmad
Dec 27 '18 at 15:24
1
How am I supposed to know what buttons you are using? Is it a ToolStripButton?
– LarsTech
Dec 27 '18 at 16:18
|
show 11 more comments
I Inerted a DGV called MarksDGV1
into my application while each cell inside of it has a default value of "0". So, after the user changes the value of some of them, when I try to reach the value for the last edited cell it gives me 0 instead of what the user typed even though it's shown correctly
(Please note: the unselected cells -which doesn't appear in Blue color- show value correctly)
How could I fix that?
Here is my code:
MarksDGV1.Refresh();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
And this is How I built the DGV:
using (DataGridViewTextBoxColumn tmp = new DataGridViewTextBoxColumn())
{
tmp.Width = 90;
tmp.ReadOnly = true;
tmp.HeaderText = "פרק מס.";
MarksDGV1.Columns.Add(tmp);
}
for (int i = 1; i <= 30; i++)
{
using (DataGridViewTextBoxColumn tmp = new DataGridViewTextBoxColumn())
{
tmp.Width = 50;
tmp.HeaderText = "שאלה מס." + i;
MarksDGV1.Columns.Add(tmp);
}
}
for (int i = 0; i < 8; i++)
{
using (DataGridViewRow tmp = (DataGridViewRow)MarksDGV1.Rows[i].Clone())
{
tmp.Cells[0].Value = i + 1;
for (int j = 1; j <= 30; j++)
{
tmp.Cells[j].Value = 0;
//tmp.Cells[j].Value = CurrentExam.Psy[i].Answers[j - 1];
}
MarksDGV1.Rows.Add(tmp);
}
}
Update: I tried typing DataGridView.Refresh();
but didn't work!
Update2: I was able to fix this by selecting another cell -different from the one that I'm concerned in- before I get the values. But that's not a solution for me
c# datagridview
New contributor
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I Inerted a DGV called MarksDGV1
into my application while each cell inside of it has a default value of "0". So, after the user changes the value of some of them, when I try to reach the value for the last edited cell it gives me 0 instead of what the user typed even though it's shown correctly
(Please note: the unselected cells -which doesn't appear in Blue color- show value correctly)
How could I fix that?
Here is my code:
MarksDGV1.Refresh();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
And this is How I built the DGV:
using (DataGridViewTextBoxColumn tmp = new DataGridViewTextBoxColumn())
{
tmp.Width = 90;
tmp.ReadOnly = true;
tmp.HeaderText = "פרק מס.";
MarksDGV1.Columns.Add(tmp);
}
for (int i = 1; i <= 30; i++)
{
using (DataGridViewTextBoxColumn tmp = new DataGridViewTextBoxColumn())
{
tmp.Width = 50;
tmp.HeaderText = "שאלה מס." + i;
MarksDGV1.Columns.Add(tmp);
}
}
for (int i = 0; i < 8; i++)
{
using (DataGridViewRow tmp = (DataGridViewRow)MarksDGV1.Rows[i].Clone())
{
tmp.Cells[0].Value = i + 1;
for (int j = 1; j <= 30; j++)
{
tmp.Cells[j].Value = 0;
//tmp.Cells[j].Value = CurrentExam.Psy[i].Answers[j - 1];
}
MarksDGV1.Rows.Add(tmp);
}
}
Update: I tried typing DataGridView.Refresh();
but didn't work!
Update2: I was able to fix this by selecting another cell -different from the one that I'm concerned in- before I get the values. But that's not a solution for me
c# datagridview
c# datagridview
New contributor
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Dec 27 '18 at 15:23
New contributor
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Dec 27 '18 at 14:54
Ahmad
1048
1048
New contributor
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Try setting the DataSource to null : datagridview1.DataSource = null; datagridview1.DataSource = dt (or what ever the source actually is)
– jdweng
Dec 27 '18 at 15:22
@RezaAghaei I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@krobelusmeetsyndra I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@jdweng I didn't use a data source to build my DGV
– Ahmad
Dec 27 '18 at 15:24
1
How am I supposed to know what buttons you are using? Is it a ToolStripButton?
– LarsTech
Dec 27 '18 at 16:18
|
show 11 more comments
Try setting the DataSource to null : datagridview1.DataSource = null; datagridview1.DataSource = dt (or what ever the source actually is)
– jdweng
Dec 27 '18 at 15:22
@RezaAghaei I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@krobelusmeetsyndra I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@jdweng I didn't use a data source to build my DGV
– Ahmad
Dec 27 '18 at 15:24
1
How am I supposed to know what buttons you are using? Is it a ToolStripButton?
– LarsTech
Dec 27 '18 at 16:18
Try setting the DataSource to null : datagridview1.DataSource = null; datagridview1.DataSource = dt (or what ever the source actually is)
– jdweng
Dec 27 '18 at 15:22
Try setting the DataSource to null : datagridview1.DataSource = null; datagridview1.DataSource = dt (or what ever the source actually is)
– jdweng
Dec 27 '18 at 15:22
@RezaAghaei I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@RezaAghaei I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@krobelusmeetsyndra I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@krobelusmeetsyndra I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@jdweng I didn't use a data source to build my DGV
– Ahmad
Dec 27 '18 at 15:24
@jdweng I didn't use a data source to build my DGV
– Ahmad
Dec 27 '18 at 15:24
1
1
How am I supposed to know what buttons you are using? Is it a ToolStripButton?
– LarsTech
Dec 27 '18 at 16:18
How am I supposed to know what buttons you are using? Is it a ToolStripButton?
– LarsTech
Dec 27 '18 at 16:18
|
show 11 more comments
1 Answer
1
active
oldest
votes
From the comments, you are using a button that doesn't take the focus away from the grid, so it remains in edit mode. Try it like this:
MarksDGV1.EndEdit();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
Thanks a lot! it worked another solution is to use .Focus();
– Ahmad
Dec 27 '18 at 16:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Ahmad is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53946928%2fdgv-doesnt-update-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
From the comments, you are using a button that doesn't take the focus away from the grid, so it remains in edit mode. Try it like this:
MarksDGV1.EndEdit();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
Thanks a lot! it worked another solution is to use .Focus();
– Ahmad
Dec 27 '18 at 16:23
add a comment |
From the comments, you are using a button that doesn't take the focus away from the grid, so it remains in edit mode. Try it like this:
MarksDGV1.EndEdit();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
Thanks a lot! it worked another solution is to use .Focus();
– Ahmad
Dec 27 '18 at 16:23
add a comment |
From the comments, you are using a button that doesn't take the focus away from the grid, so it remains in edit mode. Try it like this:
MarksDGV1.EndEdit();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
From the comments, you are using a button that doesn't take the focus away from the grid, so it remains in edit mode. Try it like this:
MarksDGV1.EndEdit();
MessageBox.Show(MarksDGV1.Rows[0].Cells[1].Value.ToString());
answered Dec 27 '18 at 16:20
LarsTech
69.5k12102154
69.5k12102154
Thanks a lot! it worked another solution is to use .Focus();
– Ahmad
Dec 27 '18 at 16:23
add a comment |
Thanks a lot! it worked another solution is to use .Focus();
– Ahmad
Dec 27 '18 at 16:23
Thanks a lot! it worked another solution is to use .Focus();
– Ahmad
Dec 27 '18 at 16:23
Thanks a lot! it worked another solution is to use .Focus();
– Ahmad
Dec 27 '18 at 16:23
add a comment |
Ahmad is a new contributor. Be nice, and check out our Code of Conduct.
Ahmad is a new contributor. Be nice, and check out our Code of Conduct.
Ahmad is a new contributor. Be nice, and check out our Code of Conduct.
Ahmad is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53946928%2fdgv-doesnt-update-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
dIr,dyOF9q,E5UK,qwzwx7vr5 fnmBNI,cyU3E,052a4IZ7 po68GhnC9,W,4WaXmKQEmWhwT
Try setting the DataSource to null : datagridview1.DataSource = null; datagridview1.DataSource = dt (or what ever the source actually is)
– jdweng
Dec 27 '18 at 15:22
@RezaAghaei I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@krobelusmeetsyndra I have Updated my post, Thanks.
– Ahmad
Dec 27 '18 at 15:24
@jdweng I didn't use a data source to build my DGV
– Ahmad
Dec 27 '18 at 15:24
1
How am I supposed to know what buttons you are using? Is it a ToolStripButton?
– LarsTech
Dec 27 '18 at 16:18