Passing multiple rows from gridview in form1 to form2 and wait for a button click












0















I have this code that have passing multiple rows from gridview in form1"FrmPaint" to form2 "OptionsPaint" after making some changes passing this data to gridview2 in form1"FrmPaint"



OptionsPaint OPaint = new OptionsPaint();        
private void btnAdd_Click(object sender, EventArgs e)
{
int selectedRows = gridView1.GetSelectedRows();
for (int i = 0; i < selectedRows.Length; i++)
{
DataRow rowGridView1 = (gridView1.GetRow(selectedRows[i]) as DataRowView).Row;
if (OPaint == null || OPaint.IsDisposed)
OPaint = new OptionsPaint();
OPaint.Show();

OPaint.bsRepere.Text = rowGridView1["BS"].ToString() + " " + "Repère: " + rowGridView1["Repère"].ToString();
OPaint.quantity.EditValue = rowGridView1["Reste Qté"];

OPaint.OK.Click += (sender1, e1) =>
{
DataRow row = dt.NewRow();
row[0] = rowGridView1["BS"];
row[1] = rowGridView1["Repère"];
row[2] = rowGridView1["Profil"];
row[3] = OPaint.quantity.EditValue;
dt.Rows.Add(row);
OPaint.Close();
};
}
}


when I select only one row the code work fine,but when I select multiple rows
the form2"OptionsPaint" show only one time with the last value selectd in gridview from from1 .is there a way to stop the code until the user click a button and then complete the rest of the code .
enter image description here










share|improve this question

























  • It is almost trivial to use a DataView where a bool column in the underlying datatable controls which form/DGV a row should display in

    – Make StackOverflow Good Again
    Dec 31 '18 at 19:18











  • I used to use this code with layoutcontrol and works well with single and multiple rows,but when I use form (form2)they didn't work for multiple rows

    – M.Bouabdallah
    Dec 31 '18 at 19:33
















0















I have this code that have passing multiple rows from gridview in form1"FrmPaint" to form2 "OptionsPaint" after making some changes passing this data to gridview2 in form1"FrmPaint"



OptionsPaint OPaint = new OptionsPaint();        
private void btnAdd_Click(object sender, EventArgs e)
{
int selectedRows = gridView1.GetSelectedRows();
for (int i = 0; i < selectedRows.Length; i++)
{
DataRow rowGridView1 = (gridView1.GetRow(selectedRows[i]) as DataRowView).Row;
if (OPaint == null || OPaint.IsDisposed)
OPaint = new OptionsPaint();
OPaint.Show();

OPaint.bsRepere.Text = rowGridView1["BS"].ToString() + " " + "Repère: " + rowGridView1["Repère"].ToString();
OPaint.quantity.EditValue = rowGridView1["Reste Qté"];

OPaint.OK.Click += (sender1, e1) =>
{
DataRow row = dt.NewRow();
row[0] = rowGridView1["BS"];
row[1] = rowGridView1["Repère"];
row[2] = rowGridView1["Profil"];
row[3] = OPaint.quantity.EditValue;
dt.Rows.Add(row);
OPaint.Close();
};
}
}


when I select only one row the code work fine,but when I select multiple rows
the form2"OptionsPaint" show only one time with the last value selectd in gridview from from1 .is there a way to stop the code until the user click a button and then complete the rest of the code .
enter image description here










share|improve this question

























  • It is almost trivial to use a DataView where a bool column in the underlying datatable controls which form/DGV a row should display in

    – Make StackOverflow Good Again
    Dec 31 '18 at 19:18











  • I used to use this code with layoutcontrol and works well with single and multiple rows,but when I use form (form2)they didn't work for multiple rows

    – M.Bouabdallah
    Dec 31 '18 at 19:33














0












0








0








I have this code that have passing multiple rows from gridview in form1"FrmPaint" to form2 "OptionsPaint" after making some changes passing this data to gridview2 in form1"FrmPaint"



OptionsPaint OPaint = new OptionsPaint();        
private void btnAdd_Click(object sender, EventArgs e)
{
int selectedRows = gridView1.GetSelectedRows();
for (int i = 0; i < selectedRows.Length; i++)
{
DataRow rowGridView1 = (gridView1.GetRow(selectedRows[i]) as DataRowView).Row;
if (OPaint == null || OPaint.IsDisposed)
OPaint = new OptionsPaint();
OPaint.Show();

OPaint.bsRepere.Text = rowGridView1["BS"].ToString() + " " + "Repère: " + rowGridView1["Repère"].ToString();
OPaint.quantity.EditValue = rowGridView1["Reste Qté"];

OPaint.OK.Click += (sender1, e1) =>
{
DataRow row = dt.NewRow();
row[0] = rowGridView1["BS"];
row[1] = rowGridView1["Repère"];
row[2] = rowGridView1["Profil"];
row[3] = OPaint.quantity.EditValue;
dt.Rows.Add(row);
OPaint.Close();
};
}
}


when I select only one row the code work fine,but when I select multiple rows
the form2"OptionsPaint" show only one time with the last value selectd in gridview from from1 .is there a way to stop the code until the user click a button and then complete the rest of the code .
enter image description here










share|improve this question
















I have this code that have passing multiple rows from gridview in form1"FrmPaint" to form2 "OptionsPaint" after making some changes passing this data to gridview2 in form1"FrmPaint"



OptionsPaint OPaint = new OptionsPaint();        
private void btnAdd_Click(object sender, EventArgs e)
{
int selectedRows = gridView1.GetSelectedRows();
for (int i = 0; i < selectedRows.Length; i++)
{
DataRow rowGridView1 = (gridView1.GetRow(selectedRows[i]) as DataRowView).Row;
if (OPaint == null || OPaint.IsDisposed)
OPaint = new OptionsPaint();
OPaint.Show();

OPaint.bsRepere.Text = rowGridView1["BS"].ToString() + " " + "Repère: " + rowGridView1["Repère"].ToString();
OPaint.quantity.EditValue = rowGridView1["Reste Qté"];

OPaint.OK.Click += (sender1, e1) =>
{
DataRow row = dt.NewRow();
row[0] = rowGridView1["BS"];
row[1] = rowGridView1["Repère"];
row[2] = rowGridView1["Profil"];
row[3] = OPaint.quantity.EditValue;
dt.Rows.Add(row);
OPaint.Close();
};
}
}


when I select only one row the code work fine,but when I select multiple rows
the form2"OptionsPaint" show only one time with the last value selectd in gridview from from1 .is there a way to stop the code until the user click a button and then complete the rest of the code .
enter image description here







c# winforms devexpress






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 19:24







M.Bouabdallah

















asked Dec 31 '18 at 19:15









M.BouabdallahM.Bouabdallah

4616




4616













  • It is almost trivial to use a DataView where a bool column in the underlying datatable controls which form/DGV a row should display in

    – Make StackOverflow Good Again
    Dec 31 '18 at 19:18











  • I used to use this code with layoutcontrol and works well with single and multiple rows,but when I use form (form2)they didn't work for multiple rows

    – M.Bouabdallah
    Dec 31 '18 at 19:33



















  • It is almost trivial to use a DataView where a bool column in the underlying datatable controls which form/DGV a row should display in

    – Make StackOverflow Good Again
    Dec 31 '18 at 19:18











  • I used to use this code with layoutcontrol and works well with single and multiple rows,but when I use form (form2)they didn't work for multiple rows

    – M.Bouabdallah
    Dec 31 '18 at 19:33

















It is almost trivial to use a DataView where a bool column in the underlying datatable controls which form/DGV a row should display in

– Make StackOverflow Good Again
Dec 31 '18 at 19:18





It is almost trivial to use a DataView where a bool column in the underlying datatable controls which form/DGV a row should display in

– Make StackOverflow Good Again
Dec 31 '18 at 19:18













I used to use this code with layoutcontrol and works well with single and multiple rows,but when I use form (form2)they didn't work for multiple rows

– M.Bouabdallah
Dec 31 '18 at 19:33





I used to use this code with layoutcontrol and works well with single and multiple rows,but when I use form (form2)they didn't work for multiple rows

– M.Bouabdallah
Dec 31 '18 at 19:33












1 Answer
1






active

oldest

votes


















1














Here is the equivalent of what your code does:



//imagine it is a form with a single label and a button
OptionsForm of = new OptionsForm();

string sa = new string{ "a","b","c" };

foreach(string s in sa){
of.Show();
of.MyLabel.Text = s;
of.MyButton.Click += (some event handler);
}


If you have 3 strings, this code loop will run completely 3 times: the first time it runs, if the OptionsForm of is not showing it will show. Repeatedly calling Show() on a form that is already visible, does nothing.



Then over the next few milliseconds the label text will be updated 3 times (so fast you won't event see it, especially as while your code is running no window messages are processed) and will finally be set to "c" - you'll never see "a" or "b". Your button click event will have 3 handlers attached to it. I'm not entirely sure if this is helpful or not, though I suspect not, as in your case it will put X rows into dt that are identical.



This is why when you select multiple rows only the last one shows; each loop passing overwrites the previous and nothing stops the loop running to completion in milliseconds



So what to do about it?



If you want this form to appear once for every selected item, so if the user selected 10 items then this form will appear 10 times in a row and they have to click 10 times to get rid of it then move the OPaint.Show() to AFTER you attach the button click event handler and make it ShowDialog instead of Show:



var dResult = OPaint.ShowDialog();


There is some additional setup you need to do to use a form as a dialog, because you need to declare which button is the OK and which is the Cancel. See this example from MSDN https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.dialogresult?view=netframework-4.7.2 - set the .dialogresult of your ok/cancel buttons and tell the form which is accept/cancel. Remove the instruction to Close() from the button click handler- buttons that control dialog type forms cause the form to close automatically when they're clicked



You'll need an if to test the dResult to know if the user clicked OK or Cancel, and handle accordingly - I don't know what you'll do if they click cancel?



Calling ShowDialog will cause the code to stop at that point until the user decides, like a messagebox does



Finally, I just want to point out that user interfaces that do this are incredibly annoying. You should consider having just one dialog that asks "ok to update all these 10 rows?" or perhaps having a single form that can show and update multiple things at once






share|improve this answer


























  • @aius Jard ,thank you very much for your help ,about showing one dialog each row has his properties(Quantity, Paint Type) must be set individually

    – M.Bouabdallah
    Jan 1 at 10:12











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53990746%2fpassing-multiple-rows-from-gridview-in-form1-to-form2-and-wait-for-a-button-clic%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









1














Here is the equivalent of what your code does:



//imagine it is a form with a single label and a button
OptionsForm of = new OptionsForm();

string sa = new string{ "a","b","c" };

foreach(string s in sa){
of.Show();
of.MyLabel.Text = s;
of.MyButton.Click += (some event handler);
}


If you have 3 strings, this code loop will run completely 3 times: the first time it runs, if the OptionsForm of is not showing it will show. Repeatedly calling Show() on a form that is already visible, does nothing.



Then over the next few milliseconds the label text will be updated 3 times (so fast you won't event see it, especially as while your code is running no window messages are processed) and will finally be set to "c" - you'll never see "a" or "b". Your button click event will have 3 handlers attached to it. I'm not entirely sure if this is helpful or not, though I suspect not, as in your case it will put X rows into dt that are identical.



This is why when you select multiple rows only the last one shows; each loop passing overwrites the previous and nothing stops the loop running to completion in milliseconds



So what to do about it?



If you want this form to appear once for every selected item, so if the user selected 10 items then this form will appear 10 times in a row and they have to click 10 times to get rid of it then move the OPaint.Show() to AFTER you attach the button click event handler and make it ShowDialog instead of Show:



var dResult = OPaint.ShowDialog();


There is some additional setup you need to do to use a form as a dialog, because you need to declare which button is the OK and which is the Cancel. See this example from MSDN https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.dialogresult?view=netframework-4.7.2 - set the .dialogresult of your ok/cancel buttons and tell the form which is accept/cancel. Remove the instruction to Close() from the button click handler- buttons that control dialog type forms cause the form to close automatically when they're clicked



You'll need an if to test the dResult to know if the user clicked OK or Cancel, and handle accordingly - I don't know what you'll do if they click cancel?



Calling ShowDialog will cause the code to stop at that point until the user decides, like a messagebox does



Finally, I just want to point out that user interfaces that do this are incredibly annoying. You should consider having just one dialog that asks "ok to update all these 10 rows?" or perhaps having a single form that can show and update multiple things at once






share|improve this answer


























  • @aius Jard ,thank you very much for your help ,about showing one dialog each row has his properties(Quantity, Paint Type) must be set individually

    – M.Bouabdallah
    Jan 1 at 10:12
















1














Here is the equivalent of what your code does:



//imagine it is a form with a single label and a button
OptionsForm of = new OptionsForm();

string sa = new string{ "a","b","c" };

foreach(string s in sa){
of.Show();
of.MyLabel.Text = s;
of.MyButton.Click += (some event handler);
}


If you have 3 strings, this code loop will run completely 3 times: the first time it runs, if the OptionsForm of is not showing it will show. Repeatedly calling Show() on a form that is already visible, does nothing.



Then over the next few milliseconds the label text will be updated 3 times (so fast you won't event see it, especially as while your code is running no window messages are processed) and will finally be set to "c" - you'll never see "a" or "b". Your button click event will have 3 handlers attached to it. I'm not entirely sure if this is helpful or not, though I suspect not, as in your case it will put X rows into dt that are identical.



This is why when you select multiple rows only the last one shows; each loop passing overwrites the previous and nothing stops the loop running to completion in milliseconds



So what to do about it?



If you want this form to appear once for every selected item, so if the user selected 10 items then this form will appear 10 times in a row and they have to click 10 times to get rid of it then move the OPaint.Show() to AFTER you attach the button click event handler and make it ShowDialog instead of Show:



var dResult = OPaint.ShowDialog();


There is some additional setup you need to do to use a form as a dialog, because you need to declare which button is the OK and which is the Cancel. See this example from MSDN https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.dialogresult?view=netframework-4.7.2 - set the .dialogresult of your ok/cancel buttons and tell the form which is accept/cancel. Remove the instruction to Close() from the button click handler- buttons that control dialog type forms cause the form to close automatically when they're clicked



You'll need an if to test the dResult to know if the user clicked OK or Cancel, and handle accordingly - I don't know what you'll do if they click cancel?



Calling ShowDialog will cause the code to stop at that point until the user decides, like a messagebox does



Finally, I just want to point out that user interfaces that do this are incredibly annoying. You should consider having just one dialog that asks "ok to update all these 10 rows?" or perhaps having a single form that can show and update multiple things at once






share|improve this answer


























  • @aius Jard ,thank you very much for your help ,about showing one dialog each row has his properties(Quantity, Paint Type) must be set individually

    – M.Bouabdallah
    Jan 1 at 10:12














1












1








1







Here is the equivalent of what your code does:



//imagine it is a form with a single label and a button
OptionsForm of = new OptionsForm();

string sa = new string{ "a","b","c" };

foreach(string s in sa){
of.Show();
of.MyLabel.Text = s;
of.MyButton.Click += (some event handler);
}


If you have 3 strings, this code loop will run completely 3 times: the first time it runs, if the OptionsForm of is not showing it will show. Repeatedly calling Show() on a form that is already visible, does nothing.



Then over the next few milliseconds the label text will be updated 3 times (so fast you won't event see it, especially as while your code is running no window messages are processed) and will finally be set to "c" - you'll never see "a" or "b". Your button click event will have 3 handlers attached to it. I'm not entirely sure if this is helpful or not, though I suspect not, as in your case it will put X rows into dt that are identical.



This is why when you select multiple rows only the last one shows; each loop passing overwrites the previous and nothing stops the loop running to completion in milliseconds



So what to do about it?



If you want this form to appear once for every selected item, so if the user selected 10 items then this form will appear 10 times in a row and they have to click 10 times to get rid of it then move the OPaint.Show() to AFTER you attach the button click event handler and make it ShowDialog instead of Show:



var dResult = OPaint.ShowDialog();


There is some additional setup you need to do to use a form as a dialog, because you need to declare which button is the OK and which is the Cancel. See this example from MSDN https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.dialogresult?view=netframework-4.7.2 - set the .dialogresult of your ok/cancel buttons and tell the form which is accept/cancel. Remove the instruction to Close() from the button click handler- buttons that control dialog type forms cause the form to close automatically when they're clicked



You'll need an if to test the dResult to know if the user clicked OK or Cancel, and handle accordingly - I don't know what you'll do if they click cancel?



Calling ShowDialog will cause the code to stop at that point until the user decides, like a messagebox does



Finally, I just want to point out that user interfaces that do this are incredibly annoying. You should consider having just one dialog that asks "ok to update all these 10 rows?" or perhaps having a single form that can show and update multiple things at once






share|improve this answer















Here is the equivalent of what your code does:



//imagine it is a form with a single label and a button
OptionsForm of = new OptionsForm();

string sa = new string{ "a","b","c" };

foreach(string s in sa){
of.Show();
of.MyLabel.Text = s;
of.MyButton.Click += (some event handler);
}


If you have 3 strings, this code loop will run completely 3 times: the first time it runs, if the OptionsForm of is not showing it will show. Repeatedly calling Show() on a form that is already visible, does nothing.



Then over the next few milliseconds the label text will be updated 3 times (so fast you won't event see it, especially as while your code is running no window messages are processed) and will finally be set to "c" - you'll never see "a" or "b". Your button click event will have 3 handlers attached to it. I'm not entirely sure if this is helpful or not, though I suspect not, as in your case it will put X rows into dt that are identical.



This is why when you select multiple rows only the last one shows; each loop passing overwrites the previous and nothing stops the loop running to completion in milliseconds



So what to do about it?



If you want this form to appear once for every selected item, so if the user selected 10 items then this form will appear 10 times in a row and they have to click 10 times to get rid of it then move the OPaint.Show() to AFTER you attach the button click event handler and make it ShowDialog instead of Show:



var dResult = OPaint.ShowDialog();


There is some additional setup you need to do to use a form as a dialog, because you need to declare which button is the OK and which is the Cancel. See this example from MSDN https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.dialogresult?view=netframework-4.7.2 - set the .dialogresult of your ok/cancel buttons and tell the form which is accept/cancel. Remove the instruction to Close() from the button click handler- buttons that control dialog type forms cause the form to close automatically when they're clicked



You'll need an if to test the dResult to know if the user clicked OK or Cancel, and handle accordingly - I don't know what you'll do if they click cancel?



Calling ShowDialog will cause the code to stop at that point until the user decides, like a messagebox does



Finally, I just want to point out that user interfaces that do this are incredibly annoying. You should consider having just one dialog that asks "ok to update all these 10 rows?" or perhaps having a single form that can show and update multiple things at once







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 1 at 16:24

























answered Jan 1 at 7:09









Caius JardCaius Jard

12k21240




12k21240













  • @aius Jard ,thank you very much for your help ,about showing one dialog each row has his properties(Quantity, Paint Type) must be set individually

    – M.Bouabdallah
    Jan 1 at 10:12



















  • @aius Jard ,thank you very much for your help ,about showing one dialog each row has his properties(Quantity, Paint Type) must be set individually

    – M.Bouabdallah
    Jan 1 at 10:12

















@aius Jard ,thank you very much for your help ,about showing one dialog each row has his properties(Quantity, Paint Type) must be set individually

– M.Bouabdallah
Jan 1 at 10:12





@aius Jard ,thank you very much for your help ,about showing one dialog each row has his properties(Quantity, Paint Type) must be set individually

– M.Bouabdallah
Jan 1 at 10:12




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53990746%2fpassing-multiple-rows-from-gridview-in-form1-to-form2-and-wait-for-a-button-clic%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith