C# populate datagridview from richtextbox

Read From textBox To DataGridview In this sample code snippet shows how to populate datagridview rows from rich text box, read all The line one by one entered in a rich textbox by foreach loop as shown and trim whitespace in both start and end of the string. Add to DataGridViewRow row with incremented row numbers.
Addition to that check if the string is numeric only and set value datagridview combobox during the loop.


Example Source Snippets - ReadFromtextBoxToDataGrid.zip

namespace : using System.Windows.Forms

How to populate datagridview row ?

        private void PopulateGridView()

            if (richTextBox1.Text != "")
                String s = String.Empty;
                int count = 0;
                foreach (string str in richTextBox1.Lines)
                    DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[count].Clone();
                    row.Cells[0].Value = str.Trim();

                    if (IsNumeric(str))
                        row.Cells[1].Value = "double";
                        row.Cells[1].Value = "string";




c# check if string is numeric only

   public static bool IsNumeric(string Expression)
            double retNum;
            bool isNum = Double.TryParse(Expression, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
            return isNum;


smartsnipps.ecomparefiles.com © 2021, All Rights Reserved | Disclaimer: smartsnipps.eCompareFiles.com is free to use any code snippets without guarantee