using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace StudentManagementSystem
{
    public partial class AddCourse : Form
    {
        public AddCourse()
        {
            InitializeComponent();
        }
        private string AddCourConnStr = "workstation id=localhost;Integrated Security=SSPI;database=StuMagSys";
        private SqlConnection AddCourConn;
        private string AddCourSql;
        private SqlCommandBuilder AddCourComm;
        private SqlDataAdapter AddCourDA;
        private DataSet AddCourseset = new DataSet();        private void AddCourse_Load(object sender, EventArgs e)
        {
         
            AddCourSql = "select Course_name as 课程名,credit as 学分 from course";
            this.AddCourConn = new SqlConnection(this.AddCourConnStr);
            this.AddCourDA = new SqlDataAdapter(this.AddCourSql, this.AddCourConn);
            AddCourseset.Clear();
            this.AddCourDA.Fill(AddCourseset, "Course");
            CourList.DataSource = AddCourseset.Tables[0];        }        private void ChgCour_Click(object sender, EventArgs e)
        {
            try
            {
                int row = this.CourList.CurrentCell.RowNumber;
                this.CourList.CurrentCell = new DataGridCell(row + 1, 0);
                if (AddCourseset.HasChanges())
                {
                    this.AddCourConn = new SqlConnection(this.AddCourConnStr);
                    this.AddCourDA = new SqlDataAdapter(this.AddCourSql, this.AddCourConn);
                    AddCourComm = new SqlCommandBuilder(AddCourDA);
                    this.AddCourDA.Update(this.AddCourseset.GetChanges(), "Course");
                    MessageBox.Show("保存修改成功!", "信息");
                }
            }
            catch (Exception Ee)
            {
                MessageBox.Show(Ee.ToString(), "信息");
            }
        }        private void ExitCour_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确认要退出本系统?", "确认", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                this.Close();
        }        private void DelCour_Click(object sender, EventArgs e)
        {
            int rowNumber = this.CourList.CurrentCell.RowNumber;
            try
            {
                this.AddCourseset.Tables[0].Rows[rowNumber].Delete();
                this.AddCourConn = new SqlConnection(this.AddCourConnStr);
                AddCourDA = new SqlDataAdapter("'", AddCourConn);
                AddCourComm = new SqlCommandBuilder(AddCourDA);
                AddCourDA.Update(this.AddCourseset.GetChanges(), "Course");
                MessageBox.Show("删除成功!", "信息");
            }
            catch
            { }
        }        private void AddCour_Click(object sender, EventArgs e)
        {
            int row=this.CourList.VisibleRowCount;
            this.CourList.CurrentCell=new DataGridCell(row+1,0);
        }        }
    }
错误System.Windows.Forms.DataGridViewCell”并不包含“RowNumber”的定义 错误无法将类型“System.Windows.Forms.DataGridCell”隐式转换为“System.Windows.Forms.DataGridViewCell” 错误“System.Windows.Forms.DataGridViewCell”并不包含“RowNumber”的定义

错误“System.Windows.Forms.DataGridView”并不包含“VisibleRowCount”的定义

解决方案 »

  1.   

    好不容易找到一个有同样错误的,怎么没有人解决呢。
    错误“System.Windows.Forms.DataGridViewCell”并不包含“RowNumber”的定义 
    只要将RowNumber改成RowIndex就可以;
    int row=this.CourList.VisibleRowCount; 
    改成int row = this.CourList.RowCount;即可,
    错误无法将类型“System.Windows.Forms.DataGridCell”隐式转换为“System.Windows.Forms.DataGridViewCell”这个问题没有解决,希望高手指点呀
      

  2.   

    顶你个肺啊,无法将类型
    “System.Windows.Forms.DataGridCell”隐式转换为“System.Windows.Forms.DataGridViewCell”
    求解