Question Display datagridview datas to richtextbox using a button

assultation

New member
Joined
Nov 10, 2014
Messages
2
Programming Experience
Beginner
First of all hi to all, I am new to this forum. I am a newbie at c# programming and no other programming experience. Please be kind to me and help me thanks . If you have any reference site that can help me or anything please do . Also english is not my native tongue so no grammar nazi pls and please understand me . Anyway...

So i have this datagridview with four columns and X number of rows. my X number of rows are indefinite and can rise and go down depending on how many data is putted. Now my question is how can i transfer all this x rows to a richtextbox by using a button my hopeful output is like this:
C#:
x1column1                     x1column2                     x1column3                  x1column4                                 
x2column1                     x2column2                     x2column3                  x2column4
x3column1                     x3column2                     x3column3                  x3column4
just imagine them being strings.
How can i achieve that?
my first impression was to use a foreach (Datarows f in DatagridView1)
but error was on foreach saying something about an enumerator.




ty and i hope u understand me..
 

Attachments

  • Screenshot (4).png
    Screenshot (4).png
    5.9 KB · Views: 40
  • Screenshot (5).png
    Screenshot (5).png
    5.1 KB · Views: 37

wim sturkenboom

Well-known member
Joined
Aug 6, 2014
Messages
85
Location
Roodepoort, South Africa
Programming Experience
10+
Both rows and columns in a datagridview can be accessed with an index like below. Below only gives you a way to iterate through rows and columns (which basically seemed to be your problem)

            for (int rowcnt = 0; rowcnt < dataGridView1.Rows.Count; rowcnt++)
            {
                for (int colcnt = 0; colcnt < dataGridView1.Columns.Count; colcnt++)
                {
                    // extract cell data here
                    object celldata = dataGridView1.Rows[rowcnt].Cells[colcnt].Value;
                    // convert to string
                    // append to textbox
                }
                // append newline to textbox for next record / row
            }
 

assultation

New member
Joined
Nov 10, 2014
Messages
2
Programming Experience
Beginner
Both rows and columns in a datagridview can be accessed with an index like below. Below only gives you a way to iterate through rows and columns (which basically seemed to be your problem)

            for (int rowcnt = 0; rowcnt < dataGridView1.Rows.Count; rowcnt++)
            {
                for (int colcnt = 0; colcnt < dataGridView1.Columns.Count; colcnt++)
                {
                    // extract cell data here
                    object celldata = dataGridView1.Rows[rowcnt].Cells[colcnt].Value;
                    // convert to string
                    // append to textbox
                }
                // append newline to textbox for next record / row
            }


Ok sir, thank you, i will study this now. i really appreciate your help
 
Top Bottom