Updating DataGridView Selected Rows
I tried to update selected rows in DataGridView, but the result is strange, it always missing a row or another. The problem is when I click btnSettled button to set the settled date, then click btnUpdate to update the database, the result seems ok, but after click btnRefresh to refresh the DGV, there is always a missing row. Is that the problem on UpdateCommand or foreach loop? Please help me to solve this problem. Thank you.
before click btnSettle
after click btnSettled and btnUpdate
after click btnRefresh
My code as follows:
DataTable dtTrx = new DataTable();
SqlDataAdapter daTrx = new SqlDataAdapter();
DataSet dsTrx = new DataSet();
public Form1()
{
InitializeComponent();
getData();
}
private void getData()
{
string strConn = "Data Source=.\xpw;Initial Catalog=MyStock;Integrated Security=True;";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string sqlTrx = "SELECT TrxID, TrxDate,Ticker,Qty,Price,Type,AccID, SettledDate,BrokerUserID FROM Trx";
daTrx = new SqlDataAdapter(sqlTrx, conn);
SqlCommandBuilder cbTrx = new SqlCommandBuilder(daTrx);
daTrx.Fill(dsTrx, "trx");
conn.Close();
dtTrx = dsTrx.Tables["trx"];
dgvTrx.DataSource = dtTrx;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
daTrx.Update(dsTrx, "trx");
}
private void btnRefresh_Click(object sender, EventArgs e)
{
dsTrx.Clear();
daTrx.Fill(dsTrx, "trx");
}
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewCell c in dgvTrx.SelectedCells)
{
dgvTrx[7, c.RowIndex].Value = "2017/7/23";
}
}
c# datagridview rows selected
add a comment |
I tried to update selected rows in DataGridView, but the result is strange, it always missing a row or another. The problem is when I click btnSettled button to set the settled date, then click btnUpdate to update the database, the result seems ok, but after click btnRefresh to refresh the DGV, there is always a missing row. Is that the problem on UpdateCommand or foreach loop? Please help me to solve this problem. Thank you.
before click btnSettle
after click btnSettled and btnUpdate
after click btnRefresh
My code as follows:
DataTable dtTrx = new DataTable();
SqlDataAdapter daTrx = new SqlDataAdapter();
DataSet dsTrx = new DataSet();
public Form1()
{
InitializeComponent();
getData();
}
private void getData()
{
string strConn = "Data Source=.\xpw;Initial Catalog=MyStock;Integrated Security=True;";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string sqlTrx = "SELECT TrxID, TrxDate,Ticker,Qty,Price,Type,AccID, SettledDate,BrokerUserID FROM Trx";
daTrx = new SqlDataAdapter(sqlTrx, conn);
SqlCommandBuilder cbTrx = new SqlCommandBuilder(daTrx);
daTrx.Fill(dsTrx, "trx");
conn.Close();
dtTrx = dsTrx.Tables["trx"];
dgvTrx.DataSource = dtTrx;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
daTrx.Update(dsTrx, "trx");
}
private void btnRefresh_Click(object sender, EventArgs e)
{
dsTrx.Clear();
daTrx.Fill(dsTrx, "trx");
}
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewCell c in dgvTrx.SelectedCells)
{
dgvTrx[7, c.RowIndex].Value = "2017/7/23";
}
}
c# datagridview rows selected
Note: If I edit SettledDate manually on DGV, then click Update and Refresh, the result is ok.
– xpw
Jul 25 '17 at 9:47
1
It would be better to loop likeforeach (DataGridViewRow r in dgvTrx.SelectedRows)
then apply the value by usingr.Cells["SettledDate"].Value = "2017/7/23";
– o_O
Jul 25 '17 at 9:48
The getData() should be triggered after the foreach loop in order to update the gridview so to speach
– Taco2
Jul 25 '17 at 9:50
@Nobody, I've just tried your suggestion, the result is just the same, missing a row. thanks.
– xpw
Jul 25 '17 at 10:00
@xpw have u tried the answer i posted?
– o_O
Jul 25 '17 at 10:02
add a comment |
I tried to update selected rows in DataGridView, but the result is strange, it always missing a row or another. The problem is when I click btnSettled button to set the settled date, then click btnUpdate to update the database, the result seems ok, but after click btnRefresh to refresh the DGV, there is always a missing row. Is that the problem on UpdateCommand or foreach loop? Please help me to solve this problem. Thank you.
before click btnSettle
after click btnSettled and btnUpdate
after click btnRefresh
My code as follows:
DataTable dtTrx = new DataTable();
SqlDataAdapter daTrx = new SqlDataAdapter();
DataSet dsTrx = new DataSet();
public Form1()
{
InitializeComponent();
getData();
}
private void getData()
{
string strConn = "Data Source=.\xpw;Initial Catalog=MyStock;Integrated Security=True;";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string sqlTrx = "SELECT TrxID, TrxDate,Ticker,Qty,Price,Type,AccID, SettledDate,BrokerUserID FROM Trx";
daTrx = new SqlDataAdapter(sqlTrx, conn);
SqlCommandBuilder cbTrx = new SqlCommandBuilder(daTrx);
daTrx.Fill(dsTrx, "trx");
conn.Close();
dtTrx = dsTrx.Tables["trx"];
dgvTrx.DataSource = dtTrx;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
daTrx.Update(dsTrx, "trx");
}
private void btnRefresh_Click(object sender, EventArgs e)
{
dsTrx.Clear();
daTrx.Fill(dsTrx, "trx");
}
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewCell c in dgvTrx.SelectedCells)
{
dgvTrx[7, c.RowIndex].Value = "2017/7/23";
}
}
c# datagridview rows selected
I tried to update selected rows in DataGridView, but the result is strange, it always missing a row or another. The problem is when I click btnSettled button to set the settled date, then click btnUpdate to update the database, the result seems ok, but after click btnRefresh to refresh the DGV, there is always a missing row. Is that the problem on UpdateCommand or foreach loop? Please help me to solve this problem. Thank you.
before click btnSettle
after click btnSettled and btnUpdate
after click btnRefresh
My code as follows:
DataTable dtTrx = new DataTable();
SqlDataAdapter daTrx = new SqlDataAdapter();
DataSet dsTrx = new DataSet();
public Form1()
{
InitializeComponent();
getData();
}
private void getData()
{
string strConn = "Data Source=.\xpw;Initial Catalog=MyStock;Integrated Security=True;";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string sqlTrx = "SELECT TrxID, TrxDate,Ticker,Qty,Price,Type,AccID, SettledDate,BrokerUserID FROM Trx";
daTrx = new SqlDataAdapter(sqlTrx, conn);
SqlCommandBuilder cbTrx = new SqlCommandBuilder(daTrx);
daTrx.Fill(dsTrx, "trx");
conn.Close();
dtTrx = dsTrx.Tables["trx"];
dgvTrx.DataSource = dtTrx;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
daTrx.Update(dsTrx, "trx");
}
private void btnRefresh_Click(object sender, EventArgs e)
{
dsTrx.Clear();
daTrx.Fill(dsTrx, "trx");
}
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewCell c in dgvTrx.SelectedCells)
{
dgvTrx[7, c.RowIndex].Value = "2017/7/23";
}
}
c# datagridview rows selected
c# datagridview rows selected
edited Jul 25 '17 at 10:17
xpw
asked Jul 25 '17 at 9:43
xpwxpw
32110
32110
Note: If I edit SettledDate manually on DGV, then click Update and Refresh, the result is ok.
– xpw
Jul 25 '17 at 9:47
1
It would be better to loop likeforeach (DataGridViewRow r in dgvTrx.SelectedRows)
then apply the value by usingr.Cells["SettledDate"].Value = "2017/7/23";
– o_O
Jul 25 '17 at 9:48
The getData() should be triggered after the foreach loop in order to update the gridview so to speach
– Taco2
Jul 25 '17 at 9:50
@Nobody, I've just tried your suggestion, the result is just the same, missing a row. thanks.
– xpw
Jul 25 '17 at 10:00
@xpw have u tried the answer i posted?
– o_O
Jul 25 '17 at 10:02
add a comment |
Note: If I edit SettledDate manually on DGV, then click Update and Refresh, the result is ok.
– xpw
Jul 25 '17 at 9:47
1
It would be better to loop likeforeach (DataGridViewRow r in dgvTrx.SelectedRows)
then apply the value by usingr.Cells["SettledDate"].Value = "2017/7/23";
– o_O
Jul 25 '17 at 9:48
The getData() should be triggered after the foreach loop in order to update the gridview so to speach
– Taco2
Jul 25 '17 at 9:50
@Nobody, I've just tried your suggestion, the result is just the same, missing a row. thanks.
– xpw
Jul 25 '17 at 10:00
@xpw have u tried the answer i posted?
– o_O
Jul 25 '17 at 10:02
Note: If I edit SettledDate manually on DGV, then click Update and Refresh, the result is ok.
– xpw
Jul 25 '17 at 9:47
Note: If I edit SettledDate manually on DGV, then click Update and Refresh, the result is ok.
– xpw
Jul 25 '17 at 9:47
1
1
It would be better to loop like
foreach (DataGridViewRow r in dgvTrx.SelectedRows)
then apply the value by using r.Cells["SettledDate"].Value = "2017/7/23";
– o_O
Jul 25 '17 at 9:48
It would be better to loop like
foreach (DataGridViewRow r in dgvTrx.SelectedRows)
then apply the value by using r.Cells["SettledDate"].Value = "2017/7/23";
– o_O
Jul 25 '17 at 9:48
The getData() should be triggered after the foreach loop in order to update the gridview so to speach
– Taco2
Jul 25 '17 at 9:50
The getData() should be triggered after the foreach loop in order to update the gridview so to speach
– Taco2
Jul 25 '17 at 9:50
@Nobody, I've just tried your suggestion, the result is just the same, missing a row. thanks.
– xpw
Jul 25 '17 at 10:00
@Nobody, I've just tried your suggestion, the result is just the same, missing a row. thanks.
– xpw
Jul 25 '17 at 10:00
@xpw have u tried the answer i posted?
– o_O
Jul 25 '17 at 10:02
@xpw have u tried the answer i posted?
– o_O
Jul 25 '17 at 10:02
add a comment |
2 Answers
2
active
oldest
votes
First of all you need start using parameterized SQL queries.
Secondly I don't see a problem with your code, but you try this :
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow r in dgvTrx.SelectedRows)
{
r.Cells["SettledDate"].Value = "2017/7/23"; //use the column name instead of column index
}
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
//the above line is added to improve the solution
//as per the link mentioned in the accepted answer
}
The reason behind this approach is that now even if you change the column position, you won't have to re-write the code to match the changes
As you are using SelectedCells
, thus unless your mouse is dragged over to the last Cell
it won't be added in the SelectedCell
collection
Note: in r.Cells["SettledDate"].Value
I assumed the column name is SettledDate
yes, your way is more elegant to maintain the code. but unfortunately the result is the same - missing a row. Thank you.
– xpw
Jul 25 '17 at 10:04
I'm sorry to hear that but I tested my code snippet now and is working for me. anyways lemme look at your code again
– o_O
Jul 25 '17 at 10:09
The selected rows are all highlighted, I think it clearly indicates which rows are selected.
– xpw
Jul 25 '17 at 10:10
Is that any problem with the underlying database table, but I think the table is quite simple.
– xpw
Jul 25 '17 at 10:13
I don't think the table is the culprit here. Although I'm still baffled that this is working for me all the way, but not for you :/
– o_O
Jul 25 '17 at 10:15
|
show 1 more comment
Finally I found the solution in :
Programmingly udpating selected rows misses the last one in dgv.DataSource.GetChanges()?
It only needs to end-edit the last row after foreach loop:
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
Thanks again to @Nobody.
Great you found the solution! I've also updated my solution to mark the changes. Also thanks to you, i learned something today ;]
– o_O
Jul 28 '17 at 17:15
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
});
}
});
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%2f45299537%2fupdating-datagridview-selected-rows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all you need start using parameterized SQL queries.
Secondly I don't see a problem with your code, but you try this :
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow r in dgvTrx.SelectedRows)
{
r.Cells["SettledDate"].Value = "2017/7/23"; //use the column name instead of column index
}
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
//the above line is added to improve the solution
//as per the link mentioned in the accepted answer
}
The reason behind this approach is that now even if you change the column position, you won't have to re-write the code to match the changes
As you are using SelectedCells
, thus unless your mouse is dragged over to the last Cell
it won't be added in the SelectedCell
collection
Note: in r.Cells["SettledDate"].Value
I assumed the column name is SettledDate
yes, your way is more elegant to maintain the code. but unfortunately the result is the same - missing a row. Thank you.
– xpw
Jul 25 '17 at 10:04
I'm sorry to hear that but I tested my code snippet now and is working for me. anyways lemme look at your code again
– o_O
Jul 25 '17 at 10:09
The selected rows are all highlighted, I think it clearly indicates which rows are selected.
– xpw
Jul 25 '17 at 10:10
Is that any problem with the underlying database table, but I think the table is quite simple.
– xpw
Jul 25 '17 at 10:13
I don't think the table is the culprit here. Although I'm still baffled that this is working for me all the way, but not for you :/
– o_O
Jul 25 '17 at 10:15
|
show 1 more comment
First of all you need start using parameterized SQL queries.
Secondly I don't see a problem with your code, but you try this :
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow r in dgvTrx.SelectedRows)
{
r.Cells["SettledDate"].Value = "2017/7/23"; //use the column name instead of column index
}
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
//the above line is added to improve the solution
//as per the link mentioned in the accepted answer
}
The reason behind this approach is that now even if you change the column position, you won't have to re-write the code to match the changes
As you are using SelectedCells
, thus unless your mouse is dragged over to the last Cell
it won't be added in the SelectedCell
collection
Note: in r.Cells["SettledDate"].Value
I assumed the column name is SettledDate
yes, your way is more elegant to maintain the code. but unfortunately the result is the same - missing a row. Thank you.
– xpw
Jul 25 '17 at 10:04
I'm sorry to hear that but I tested my code snippet now and is working for me. anyways lemme look at your code again
– o_O
Jul 25 '17 at 10:09
The selected rows are all highlighted, I think it clearly indicates which rows are selected.
– xpw
Jul 25 '17 at 10:10
Is that any problem with the underlying database table, but I think the table is quite simple.
– xpw
Jul 25 '17 at 10:13
I don't think the table is the culprit here. Although I'm still baffled that this is working for me all the way, but not for you :/
– o_O
Jul 25 '17 at 10:15
|
show 1 more comment
First of all you need start using parameterized SQL queries.
Secondly I don't see a problem with your code, but you try this :
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow r in dgvTrx.SelectedRows)
{
r.Cells["SettledDate"].Value = "2017/7/23"; //use the column name instead of column index
}
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
//the above line is added to improve the solution
//as per the link mentioned in the accepted answer
}
The reason behind this approach is that now even if you change the column position, you won't have to re-write the code to match the changes
As you are using SelectedCells
, thus unless your mouse is dragged over to the last Cell
it won't be added in the SelectedCell
collection
Note: in r.Cells["SettledDate"].Value
I assumed the column name is SettledDate
First of all you need start using parameterized SQL queries.
Secondly I don't see a problem with your code, but you try this :
private void btnSettled_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow r in dgvTrx.SelectedRows)
{
r.Cells["SettledDate"].Value = "2017/7/23"; //use the column name instead of column index
}
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
//the above line is added to improve the solution
//as per the link mentioned in the accepted answer
}
The reason behind this approach is that now even if you change the column position, you won't have to re-write the code to match the changes
As you are using SelectedCells
, thus unless your mouse is dragged over to the last Cell
it won't be added in the SelectedCell
collection
Note: in r.Cells["SettledDate"].Value
I assumed the column name is SettledDate
edited Jul 28 '17 at 17:14
answered Jul 25 '17 at 9:57
o_Oo_O
2,16531531
2,16531531
yes, your way is more elegant to maintain the code. but unfortunately the result is the same - missing a row. Thank you.
– xpw
Jul 25 '17 at 10:04
I'm sorry to hear that but I tested my code snippet now and is working for me. anyways lemme look at your code again
– o_O
Jul 25 '17 at 10:09
The selected rows are all highlighted, I think it clearly indicates which rows are selected.
– xpw
Jul 25 '17 at 10:10
Is that any problem with the underlying database table, but I think the table is quite simple.
– xpw
Jul 25 '17 at 10:13
I don't think the table is the culprit here. Although I'm still baffled that this is working for me all the way, but not for you :/
– o_O
Jul 25 '17 at 10:15
|
show 1 more comment
yes, your way is more elegant to maintain the code. but unfortunately the result is the same - missing a row. Thank you.
– xpw
Jul 25 '17 at 10:04
I'm sorry to hear that but I tested my code snippet now and is working for me. anyways lemme look at your code again
– o_O
Jul 25 '17 at 10:09
The selected rows are all highlighted, I think it clearly indicates which rows are selected.
– xpw
Jul 25 '17 at 10:10
Is that any problem with the underlying database table, but I think the table is quite simple.
– xpw
Jul 25 '17 at 10:13
I don't think the table is the culprit here. Although I'm still baffled that this is working for me all the way, but not for you :/
– o_O
Jul 25 '17 at 10:15
yes, your way is more elegant to maintain the code. but unfortunately the result is the same - missing a row. Thank you.
– xpw
Jul 25 '17 at 10:04
yes, your way is more elegant to maintain the code. but unfortunately the result is the same - missing a row. Thank you.
– xpw
Jul 25 '17 at 10:04
I'm sorry to hear that but I tested my code snippet now and is working for me. anyways lemme look at your code again
– o_O
Jul 25 '17 at 10:09
I'm sorry to hear that but I tested my code snippet now and is working for me. anyways lemme look at your code again
– o_O
Jul 25 '17 at 10:09
The selected rows are all highlighted, I think it clearly indicates which rows are selected.
– xpw
Jul 25 '17 at 10:10
The selected rows are all highlighted, I think it clearly indicates which rows are selected.
– xpw
Jul 25 '17 at 10:10
Is that any problem with the underlying database table, but I think the table is quite simple.
– xpw
Jul 25 '17 at 10:13
Is that any problem with the underlying database table, but I think the table is quite simple.
– xpw
Jul 25 '17 at 10:13
I don't think the table is the culprit here. Although I'm still baffled that this is working for me all the way, but not for you :/
– o_O
Jul 25 '17 at 10:15
I don't think the table is the culprit here. Although I'm still baffled that this is working for me all the way, but not for you :/
– o_O
Jul 25 '17 at 10:15
|
show 1 more comment
Finally I found the solution in :
Programmingly udpating selected rows misses the last one in dgv.DataSource.GetChanges()?
It only needs to end-edit the last row after foreach loop:
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
Thanks again to @Nobody.
Great you found the solution! I've also updated my solution to mark the changes. Also thanks to you, i learned something today ;]
– o_O
Jul 28 '17 at 17:15
add a comment |
Finally I found the solution in :
Programmingly udpating selected rows misses the last one in dgv.DataSource.GetChanges()?
It only needs to end-edit the last row after foreach loop:
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
Thanks again to @Nobody.
Great you found the solution! I've also updated my solution to mark the changes. Also thanks to you, i learned something today ;]
– o_O
Jul 28 '17 at 17:15
add a comment |
Finally I found the solution in :
Programmingly udpating selected rows misses the last one in dgv.DataSource.GetChanges()?
It only needs to end-edit the last row after foreach loop:
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
Thanks again to @Nobody.
Finally I found the solution in :
Programmingly udpating selected rows misses the last one in dgv.DataSource.GetChanges()?
It only needs to end-edit the last row after foreach loop:
this.BindingContext[dgvTrx.DataSource].EndCurrentEdit();
Thanks again to @Nobody.
edited Jul 29 '17 at 17:27
o_O
2,16531531
2,16531531
answered Jul 26 '17 at 3:15
xpwxpw
32110
32110
Great you found the solution! I've also updated my solution to mark the changes. Also thanks to you, i learned something today ;]
– o_O
Jul 28 '17 at 17:15
add a comment |
Great you found the solution! I've also updated my solution to mark the changes. Also thanks to you, i learned something today ;]
– o_O
Jul 28 '17 at 17:15
Great you found the solution! I've also updated my solution to mark the changes. Also thanks to you, i learned something today ;]
– o_O
Jul 28 '17 at 17:15
Great you found the solution! I've also updated my solution to mark the changes. Also thanks to you, i learned something today ;]
– o_O
Jul 28 '17 at 17:15
add a comment |
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.
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%2f45299537%2fupdating-datagridview-selected-rows%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
Note: If I edit SettledDate manually on DGV, then click Update and Refresh, the result is ok.
– xpw
Jul 25 '17 at 9:47
1
It would be better to loop like
foreach (DataGridViewRow r in dgvTrx.SelectedRows)
then apply the value by usingr.Cells["SettledDate"].Value = "2017/7/23";
– o_O
Jul 25 '17 at 9:48
The getData() should be triggered after the foreach loop in order to update the gridview so to speach
– Taco2
Jul 25 '17 at 9:50
@Nobody, I've just tried your suggestion, the result is just the same, missing a row. thanks.
– xpw
Jul 25 '17 at 10:00
@xpw have u tried the answer i posted?
– o_O
Jul 25 '17 at 10:02