我的窗体时嵌入到panel中的,但是嵌入后发现无法控制datagridview控件的行只读,也就是说嵌入后行只读设置失效,大家有什么好的解决方法吗?代码如下:
1.设置只读行(目的是让控制用户值能够一行一行顺序输入,不能够跳行输入)        private void SetValue()
        {
            DataSet dsResult = new DataSet();
            using (SqlConnection con = new SqlConnection("data source =.;database=Test;User Id=eu;Pwd=123;"))
            {
                SqlCommand cmd = new SqlCommand("SELECT  [id],[name],[address],[schoolid],[sex] FROM [student];SELECT  [schoolid],[schoolName] FROM [school]");
                con.Open();
                cmd.Connection = con;
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                try
                {
                    adapter.Fill(dsResult);
                    con.Close();
                }
                catch
                {
                    con.Close();
                    dsResult = null;
                }
            }
            if (dsResult != null && dsResult.Tables.Count > 0)
            {
                DataGridView dgv = dgvs["dgv"];
                //
                DataTable dt = dsResult.Tables[0];
                int count = dsResult.Tables[0].Rows.Count;                for (int i = 0; i < 30; i++)
                {
                    dsResult.Tables[0].Rows.Add(dsResult.Tables[0].NewRow());
                }
                BindingSource bindingSource = new BindingSource();
                bindingSource.DataSource = dt;
                dgv.DataSource = bindingSource;
                //
                for (int i = count + 1; i < dgv.Rows.Count; i++)
                {
                    dgv.Rows[i].ReadOnly = true;
                }
            }
        }2.把窗体嵌入到panel中(提供类似ie8模式的操作界面,方便用户录入数据的时候查看相关数据)
            string path = Assembly.GetExecutingAssembly().Location;
            path = path.Remove(path.LastIndexOf("\\")) + "\\WinForm.dll";
            Assembly assembly = Assembly.LoadFile(path);
            Type type = assembly.GetType("WinForm.FormGridTest");
            Form frm = Activator.CreateInstance(type) as Form;
            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.TopLevel = false;
            frm.Parent = panel2;
            frm.Location = new Point(0, 0);
            frm.Dock = DockStyle.Fill;
            frm.Show();
嵌入panel后行只读设置失效。
如下的模态窗体倒是可以控制行只读            string path = Assembly.GetExecutingAssembly().Location;
            path = path.Remove(path.LastIndexOf("\\")) + "\\WinForm.dll";
            Assembly assembly = Assembly.LoadFile(path);
            Type type = assembly.GetType("WinForm.FormGridTest");
            Form frm = Activator.CreateInstance(type) as Form;
            //frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            //frm.TopLevel = false;
            //frm.Parent = panel2;
            //frm.Location = new Point(0, 0);
            //frm.Dock = DockStyle.Fill;
            frm.Show();太郁闷了。大家有什么好的解决方法吗?