0

enter image description here enter image description here


My code; All i wanted is to copy the format that was done on the richbox on the right and implement it in a datagridview, can somebody give me a hand? The DGV on the bottom should have only 1 column which is named "Notifcation" and below it are the example data to be found in the richtextbox.

Or a new way to discharge unnecessary blank row in the first DGV? and put them all together in one column same as the presentation of the richtextbox?

        DataTable dt_new = new DataTable();
        dt_new.Merge(dt1, true, MissingSchemaAction.Add);
        dt_new.Merge(dt2, true, MissingSchemaAction.Add);
        dt_new.Merge(dt3, true, MissingSchemaAction.Add);
        dgv4.DataSource = dt_new;


         String a = dt1.Rows.Count.ToString();
         String s = dt2.Rows.Count.ToString();
         String d = dt3.Rows.Count.ToString();

        int z = Int32.Parse(a);
        int x = Int32.Parse(s);
        int c = Int32.Parse(d);

        int sum = z + x + c;

        CANT.Text = sum.ToString();


        //richtextbox
        for (int i = 0; i < dgv4.Rows.Count - 1; i++)
        {

            richTextBox1.Text = richTextBox1.Text;

            for (int j = 0; j < dgv4.Columns.Count; j++)
            {

                richTextBox1.Text = richTextBox1.Text + dgv4.Rows[i].Cells[j].Value.ToString();

            }

            richTextBox1.Text = richTextBox1.Text + "\n";

        }`
  • I find the question very unclear... According to the code, you have 3 DataTables, which you merge into one, then you want to use this data and create one list of "Notifications", is that right? Could you share the original data in the datatables and explain what information you want to extract into "notifications". – Esko Aug 28 '18 at 06:01
  • "...Then you want to use this data and create one list of "Notifications", is that right?" Yes. Almost every information in each datatables, in tab no.4 i was able to "merge" them but the problem for me is all i want is only one column which is the "Notification" each column name from the other datatable was also included and there are blank cells that i want to get rid of. I'll upload a picutre of the 3 datatables. –  Aug 28 '18 at 06:04
  • Ok, I understand. But I still don't know what information from the 3 DataTables you wish to include in the notification? Also how does the data in 3 separate DataTables relate to each other? – Esko Aug 28 '18 at 06:19
  • They came from 3 different queries (tables) –  Aug 28 '18 at 06:27
  • 1st DT columnnames = itemname & quantity / 2nd DT columnnames = stock & cl / 3rd DT columnnames = date –  Aug 28 '18 at 06:37
  • Why woulnd't you just join the tables in sql-query and get only the columns/data you need? This kind of job should not be done in the front end application, just create a specific sql-clause with joins (inner/outer etc) between the tables and add a relevant where-clause if needed. Assuming of course that the data is in database and not in csv or something:) – Esko Aug 28 '18 at 06:41
  • Alright i'll try to do that, thank you. –  Aug 28 '18 at 06:47

1 Answers1

1

Try to set DefaultCellStyle.WrapMode property of DataGridViewColumn to DataGridViewTriState.True

dgv1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgv1.Columns["columnName"].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

Then replace "\n" with Environment.NewLine in below line of code when added line break in the text:

richTextBox1.Text = richTextBox1.Text + "\n";

If it does not fulfill your requirement then handling the DataGridView_CellFormatting event and formatting the text as required.

References:
C#: multiline text in DataGridView control

Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75