c# value from all selected rows DataGridView











up vote
-2
down vote

favorite












Right now I have a DataGridView which displays data from mySQL. I would like to display data from specific cells for all selected rows in TextBox.



Eg, user selected row 1, 3 and 4:



        column 1 / column 2 / column 3
row 1 : model1 / serial1 / cpu1
row 2 : model2 / serial2 / cpu2
row 3 : model3 / serial3 / cpu3
row 4 : model4 / serial4 / cpu4


output in textbox "serial" will be:



serial1
serial3
serial4


I assume I need to use SelectionChanged. Right now I could only display selected cell.



private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
{
int index = e.RowIndex;
DataGridViewRow selectedRow= dataGridView2.Rows[index];
MessageBox.Show(selectedRow.Cells[4].Value.ToString());
}









share|improve this question
























  • You don't want to set the selected row, you want to get the selected rows so you can read their data. Are you having a problem allowing multiple row selections or are you all set with that part?
    – Crowcoder
    Nov 19 at 18:22










  • Looks like you want the column of the cell that was selected. The DataGridViewCellEventArgs has a ColumnIndex property that may help.
    – mcdon
    Nov 19 at 18:23










  • I dont really know how to get data from multiple selected rows. and i dont really know how to write code here. :(
    – Filip Be
    Nov 19 at 18:28










  • @mcdon It looks like OP knows how to find the column and that would require the user to click on correct column instead of any.
    – Crowcoder
    Nov 19 at 18:28












  • @FilipBe just loop over dataGridView2.SelectedRows and grab values like you are doing in the message box.
    – Crowcoder
    Nov 19 at 18:30

















up vote
-2
down vote

favorite












Right now I have a DataGridView which displays data from mySQL. I would like to display data from specific cells for all selected rows in TextBox.



Eg, user selected row 1, 3 and 4:



        column 1 / column 2 / column 3
row 1 : model1 / serial1 / cpu1
row 2 : model2 / serial2 / cpu2
row 3 : model3 / serial3 / cpu3
row 4 : model4 / serial4 / cpu4


output in textbox "serial" will be:



serial1
serial3
serial4


I assume I need to use SelectionChanged. Right now I could only display selected cell.



private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
{
int index = e.RowIndex;
DataGridViewRow selectedRow= dataGridView2.Rows[index];
MessageBox.Show(selectedRow.Cells[4].Value.ToString());
}









share|improve this question
























  • You don't want to set the selected row, you want to get the selected rows so you can read their data. Are you having a problem allowing multiple row selections or are you all set with that part?
    – Crowcoder
    Nov 19 at 18:22










  • Looks like you want the column of the cell that was selected. The DataGridViewCellEventArgs has a ColumnIndex property that may help.
    – mcdon
    Nov 19 at 18:23










  • I dont really know how to get data from multiple selected rows. and i dont really know how to write code here. :(
    – Filip Be
    Nov 19 at 18:28










  • @mcdon It looks like OP knows how to find the column and that would require the user to click on correct column instead of any.
    – Crowcoder
    Nov 19 at 18:28












  • @FilipBe just loop over dataGridView2.SelectedRows and grab values like you are doing in the message box.
    – Crowcoder
    Nov 19 at 18:30















up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











Right now I have a DataGridView which displays data from mySQL. I would like to display data from specific cells for all selected rows in TextBox.



Eg, user selected row 1, 3 and 4:



        column 1 / column 2 / column 3
row 1 : model1 / serial1 / cpu1
row 2 : model2 / serial2 / cpu2
row 3 : model3 / serial3 / cpu3
row 4 : model4 / serial4 / cpu4


output in textbox "serial" will be:



serial1
serial3
serial4


I assume I need to use SelectionChanged. Right now I could only display selected cell.



private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
{
int index = e.RowIndex;
DataGridViewRow selectedRow= dataGridView2.Rows[index];
MessageBox.Show(selectedRow.Cells[4].Value.ToString());
}









share|improve this question















Right now I have a DataGridView which displays data from mySQL. I would like to display data from specific cells for all selected rows in TextBox.



Eg, user selected row 1, 3 and 4:



        column 1 / column 2 / column 3
row 1 : model1 / serial1 / cpu1
row 2 : model2 / serial2 / cpu2
row 3 : model3 / serial3 / cpu3
row 4 : model4 / serial4 / cpu4


output in textbox "serial" will be:



serial1
serial3
serial4


I assume I need to use SelectionChanged. Right now I could only display selected cell.



private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
{
int index = e.RowIndex;
DataGridViewRow selectedRow= dataGridView2.Rows[index];
MessageBox.Show(selectedRow.Cells[4].Value.ToString());
}






c# dataview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 21:23









fnascimento

7211014




7211014










asked Nov 19 at 18:14









Filip Be

13




13












  • You don't want to set the selected row, you want to get the selected rows so you can read their data. Are you having a problem allowing multiple row selections or are you all set with that part?
    – Crowcoder
    Nov 19 at 18:22










  • Looks like you want the column of the cell that was selected. The DataGridViewCellEventArgs has a ColumnIndex property that may help.
    – mcdon
    Nov 19 at 18:23










  • I dont really know how to get data from multiple selected rows. and i dont really know how to write code here. :(
    – Filip Be
    Nov 19 at 18:28










  • @mcdon It looks like OP knows how to find the column and that would require the user to click on correct column instead of any.
    – Crowcoder
    Nov 19 at 18:28












  • @FilipBe just loop over dataGridView2.SelectedRows and grab values like you are doing in the message box.
    – Crowcoder
    Nov 19 at 18:30




















  • You don't want to set the selected row, you want to get the selected rows so you can read their data. Are you having a problem allowing multiple row selections or are you all set with that part?
    – Crowcoder
    Nov 19 at 18:22










  • Looks like you want the column of the cell that was selected. The DataGridViewCellEventArgs has a ColumnIndex property that may help.
    – mcdon
    Nov 19 at 18:23










  • I dont really know how to get data from multiple selected rows. and i dont really know how to write code here. :(
    – Filip Be
    Nov 19 at 18:28










  • @mcdon It looks like OP knows how to find the column and that would require the user to click on correct column instead of any.
    – Crowcoder
    Nov 19 at 18:28












  • @FilipBe just loop over dataGridView2.SelectedRows and grab values like you are doing in the message box.
    – Crowcoder
    Nov 19 at 18:30


















You don't want to set the selected row, you want to get the selected rows so you can read their data. Are you having a problem allowing multiple row selections or are you all set with that part?
– Crowcoder
Nov 19 at 18:22




You don't want to set the selected row, you want to get the selected rows so you can read their data. Are you having a problem allowing multiple row selections or are you all set with that part?
– Crowcoder
Nov 19 at 18:22












Looks like you want the column of the cell that was selected. The DataGridViewCellEventArgs has a ColumnIndex property that may help.
– mcdon
Nov 19 at 18:23




Looks like you want the column of the cell that was selected. The DataGridViewCellEventArgs has a ColumnIndex property that may help.
– mcdon
Nov 19 at 18:23












I dont really know how to get data from multiple selected rows. and i dont really know how to write code here. :(
– Filip Be
Nov 19 at 18:28




I dont really know how to get data from multiple selected rows. and i dont really know how to write code here. :(
– Filip Be
Nov 19 at 18:28












@mcdon It looks like OP knows how to find the column and that would require the user to click on correct column instead of any.
– Crowcoder
Nov 19 at 18:28






@mcdon It looks like OP knows how to find the column and that would require the user to click on correct column instead of any.
– Crowcoder
Nov 19 at 18:28














@FilipBe just loop over dataGridView2.SelectedRows and grab values like you are doing in the message box.
– Crowcoder
Nov 19 at 18:30






@FilipBe just loop over dataGridView2.SelectedRows and grab values like you are doing in the message box.
– Crowcoder
Nov 19 at 18:30



















active

oldest

votes











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',
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%2f53380448%2fc-sharp-value-from-all-selected-rows-datagridview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















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.





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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380448%2fc-sharp-value-from-all-selected-rows-datagridview%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

Wiesbaden

Marschland

Dieringhausen