Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have 10 column in my datagridview. I want to get whole value from row(which row i'll select).

I have this code but it's shows only one cell value:
C#
richtextbox.Text = dataGridView1.CurrentCell.Value.ToString();
Posted
Updated 18-Feb-13 6:04am
v2
Comments
Richard C Bishop 18-Feb-13 12:07pm    
You are using CurrentCell, that will limit you to the cell you selected. You will need to elaborate a bit more on what you are trying to accomplish please.

1 solution

hey dude!
i have a solution for your question! i hope help you ...
here we have a foreach to check any cell of selected rows of datagridview .
an int variable will count cells untill foreach arrive to last cell!
we have an indexer into DataGridViewRow Class that return value of cells which counter specified!
C#
int counter=0;
            foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
            {
                richtextbox.Text +=dr.Cells[counter].Value.ToString();
            }


hope help you!
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 18-Feb-13 18:24pm    
What an abuse! 9 nearly identical lines... What, not a clue?
—SA
ali_heidari_ 18-Feb-13 18:37pm    
dude , this is just a sample to show how it works! i know its so messy! anyway its not good reason to downvote!
Sergey Alexandrovich Kryukov 18-Feb-13 18:47pm    
Well, I'm not sure. Do you know how to make it not messy? Do you understand you give a bad sample to the beginners?
Actually, making it not messy was the only problem, as assigning a value to Text is too trivial, you could just give a link instead of this code.
Also, you "code" won't even compile. It's not good to confuse naive readers so much, don't you think so?
—SA
ali_heidari_ 18-Feb-13 18:54pm    
you are right, i have a mistake in my sample!
i am not trying to make readers confusing! and try to post answers in best way!
Sergey Alexandrovich Kryukov 18-Feb-13 18:56pm    
Oh sure, I don't know and will quite gladly give you high vote it you fix it! Nothing personal, consider I just wanted to fix things or help to fix.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900