C#substring到DataGridView

时间:2014-02-16 23:45:14

标签: c# winforms datagridview

我有一个字符串,我需要分解成部分并显示到DataGridView中。我能够基本上打破字符串,但我不知道如何将其添加到DataGridView。有什么帮助吗?

if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            try
            {
                if ((myStream = ofd.OpenFile()) != null)
                {
                    using (StreamReader sr = new StreamReader(myStream))
                    {
                        while ((line = sr.ReadLine()) != null)
                        {
                            line = "00000E51C2F21EDDAD458ECA06E4BF5496E6B3F2CE2517B5F3AD3ECC6D43C51A67FF285CF7E5CF29";                               

                            //Count each line as a cluster
                            counter += 1;

                            string frame = line.Substring(0, 2);
                            ConvertedBinary = Convert.ToString(Convert.ToInt32(frame, 16), 2).PadLeft(8, '0');
                            string mType = ConvertedBinary.Substring(6, 2);

                            /////////////////////////////Manufactor Type
                            switch (mType)
                            {
                                case "00":
                                    dataGridaViewParse.Row[1][2].ToString("Entire Profile");
                                    break;
                                case "01":
                                    dataGridaViewParse.Row[1][2].ToString("Cluster");
                                    break;
                                case "10":
                                    dataGridaViewParse.Row[1][2].ToString("Reserved");
                                    break;
                                case "11":
                                    dataGridaViewParse.Row[1][2].ToString("Reserved");
                                    break;
                                default:
                                    dataGridaViewParse.Row[1][2].ToString("error");
                                    break;
                            }
                        }
                    }
                }

1 个答案:

答案 0 :(得分:0)

Me.dataGridView1.Rows.Add(“五”,“六”,“七”,“八”) Me.dataGridView1.Rows.Insert(0,“one”,“two”,“three”,“four”)

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx