Click here to Skip to main content
13,559,193 members
Rate this:
Please Sign up or sign in to 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:
richtextbox.Text = dataGridView1.CurrentCell.Value.ToString();
Posted 18-Feb-13 6:02am
Updated 18-Feb-13 6:04am
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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!
int counter=0;
            foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
                richtextbox.Text +=dr.Cells[counter].Value.ToString();

hope help you!
Sergey Alexandrovich Kryukov 18-Feb-13 18:24pm
What an abuse! 9 nearly identical lines... What, not a clue?
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?
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.
ali_heidari_ 18-Feb-13 19:00pm
thanks ! it was my fault sorry !
Sergey Alexandrovich Kryukov 18-Feb-13 19:12pm
My 4. Probably, you also need to insert a line separator, or something like this.

The problem with some 9 instances of RichTextBox is not so trivial. First of all, having so many is a sign of wrong UI design. Let's assume it's really needed. Then the mistake would be creating then all using the Designer. It would inevitably lead to a lot of manual work and lack of supportability. Instead, all such controls should be created in code, where an array can be used. That would be a good solution.

ali_heidari_ 18-Feb-13 19:17pm
very thanks for your guidance! but really keeping 10 richtextbox was not my solution, i know it wastes time! i just thought "arvindnitin7" have 10 richtextbox in his form, so i wrote something fit with that!
Sergey Alexandrovich Kryukov 18-Feb-13 19:23pm
It might not be your idea, but OP also does not mean multiple edit control, maybe you misunderstood it. I have you an idea how to deal with that. And OP now should have a good idea on the resolution of that simple problem.
Thanks for your understanding and fixing the answer; I appreciate it.
Sergey Alexandrovich Kryukov 18-Feb-13 18:52pm
Besides, I've just found you were cheating with answers: you ask a "question", provide "answer" by yourself and even formally accept it. Why would you do so? By doing such thing, you make yourself a candidate for revocation of your CodeProject account.
You should understand it: if you answer question, you need to take serious responsibility.
ali_heidari_ 18-Feb-13 18:57pm
but really for my messy ,i am candidate for revocation my codeproject account? really why? why you think i am cheating with answers?
Sergey Alexandrovich Kryukov 18-Feb-13 19:16pm
No. Let me explain: after your comments, I looked at some of your answers, and found that in some cases, you answered your own questions, and even self-accepted them formally. Why?
I can tell you: there is a number of case when members lost their accounts, as a result of abuse reports. Please understand: anyone can generate any number of "questions", "answer" them and accept them formally to get points. Some artists did that, was caught, reported for abuse be several members, which led to cancellation of accounts.
I don't think your abuse is that heavy, so I would rather warn you about it and remove improper posts, but then you need to be careful.
ali_heidari_ 18-Feb-13 19:22pm
i was novice in codeproject! i never forgot your guidance!
Sergey Alexandrovich Kryukov 18-Feb-13 19:23pm
I would prefer you fix it.
Anyway, thanks for your understanding.
ali_heidari_ 18-Feb-13 19:35pm
i always respect to you!
Joezer BH 19-Feb-13 0:31am
After all this, you guys should definitely get a beer, if it's technically possible :idea:

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180515.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100