Shesh Mishra

Shesh Mishra

  • NA
  • 22
  • 31.9k

Solve the error in the code

Aug 1 2012 4:28 AM
Error    1    Using the generic type 'System.Collections.Generic.List<T>' requires 1 type argument Line 90 Col 13

Error    2    Using the generic type 'System.Collections.Generic.List<T>' requires 1 type argument Line 90 Col 33

Form design

Images


Code Behind

 


using System.Data;
namespace SelChkRowVal
{
    public partial class Form1 : Form
    {
        DataTable dt = new DataTable();
        DataRow dr;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            loadGrid();
        }

        public void loadGrid()
        {
            dataGridView1.AllowUserToAddRows = false;

            //Below i create on check box column in the datagrid view
            dataGridView1.Columns.Clear();
            DataGridViewCheckBoxColumn colCB = new DataGridViewCheckBoxColumn();
            //set name for the check box column
            colCB.Name = "chkcol";
            colCB.HeaderText = "";

            dataGridView1.Columns.Add(colCB);

            DataTable dt = new DataTable();
            DataRow dr = default(DataRow);

            //Declare Column names
            dt.Columns.Add("eno");
            dt.Columns.Add("empname");
            dt.Columns.Add("sal");

            //Create rows with data
            dr = dt.NewRow();
            dr["eno"] = 101;
            dr["empname"] = "test1";
            dr["sal"] = 9000;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["eno"] = 102;
            dr["empname"] = "test2";
            dr["sal"] = 15000;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["eno"] = 103;
            dr["empname"] = "test3";
            dr["sal"] = 20000;
            dt.Rows.Add(dr);

            dataGridView1.DataSource = dt;
        }    
        //Below method is used check only one checkbox in grid view
        private void dataGridView1_CellClick(System.Object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                if (Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells["chkcol"].Value) == false)
                {
                    for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++)
                    {
                        dataGridView1.Rows[i].Cells["chkcol"].Value = false;
                    }
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text="";

            int i = 0;
            List ChkedRow = new List();

            for (i = 0; i <= dataGridView1.RowCount - 1; i++)
            {
                if (Convert.ToBoolean(dataGridView1.Rows[i].Cells["chkcol"].Value) == true)
                {
                    ChkedRow.Add(i);
                }
            }

            if (ChkedRow.Count == 0)
            {
                MessageBox.Show("Select atleast one checkbox");
                return;
            }

            //Here i display all selected checkbox data in that three text boxes
            foreach (int k in ChkedRow)
            {
                textBox1.Text = textBox1.Text + dataGridView1.Rows[k].Cells[1].Value + " ";
                textBox2.Text = textBox2.Text + dataGridView1.Rows[k].Cells[2].Value + " ";
                textBox3.Text = textBox3.Text + dataGridView1.Rows[k].Cells[3].Value + " ";
            }
        }
    }
}



Answers (2)