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());
}
c# dataview
|
show 5 more comments
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());
}
c# dataview
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 overdataGridView2.SelectedRows
and grab values like you are doing in the message box.
– Crowcoder
Nov 19 at 18:30
|
show 5 more comments
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());
}
c# dataview
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
c# dataview
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 overdataGridView2.SelectedRows
and grab values like you are doing in the message box.
– Crowcoder
Nov 19 at 18:30
|
show 5 more comments
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 overdataGridView2.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
|
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53380448%2fc-sharp-value-from-all-selected-rows-datagridview%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
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