Vikas Ahlawat

Vikas Ahlawat

  • NA
  • 564
  • 817k

How change the indexed of the columns which is filled by dataset , in datagridview?

Oct 26 2009 5:51 AM


code i have used

 private void Form_Attendence_Taken_Load(object sender, EventArgs e)
        {
            ATcomboBox_Class.SelectedIndex = 0;
            ATcomboBoxSection.SelectedIndex = 0;
            con.Open();
            //dataGridView1.Columns["Column1"].DisplayIndex = 4;
            //dataGridView1.Columns["Column2"].DisplayIndex = 5;
            //dataGridView1.Columns["Column3"].DisplayIndex = 6;
            //dataGridView1.Columns["Column4"].DisplayIndex = 7;
            //dataGridView1.Columns["Column5"].DisplayIndex = 8;
            //dataGridView1.Columns["Column6"].DisplayIndex = 9;
            //dataGridView1.Columns["Column7"].DisplayIndex = 10;
            //dataGridView1.Columns["Column8"].DisplayIndex = 11;
            //dataGridView1.Columns["Column9"].DisplayIndex = 12;
            //dataGridView1.Columns["Column10"].DisplayIndex = 13;


            SqlCommand cmd0 = new SqlCommand("select * from View_2", con);
            //cmd0.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da0 = new SqlDataAdapter(cmd0);
            DataSet ds0 = new DataSet();
            da0.Fill(ds0, "Attendance");
            dataGridView1.DataSource = ds0.Tables["Attendance"];
            DataGridViewCheckBoxColumn P1_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P2_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P3_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P4_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P5_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P6_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P7_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P8_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P9_checkbox = new DataGridViewCheckBoxColumn();
            DataGridViewCheckBoxColumn P10_checkbox = new DataGridViewCheckBoxColumn();
            P1_checkbox.HeaderText = "I";
            P2_checkbox.HeaderText = "II";
            P3_checkbox.HeaderText = "III";
            P4_checkbox.HeaderText = "IV";
            P5_checkbox.HeaderText = "V";
            P6_checkbox.HeaderText = "VI";
            P7_checkbox.HeaderText = "VII";
            P8_checkbox.HeaderText = "VIII";
            P9_checkbox.HeaderText = "IX";
            P10_checkbox.HeaderText = "X";
            dataGridView1.Columns.Add(P1_checkbox);
            dataGridView1.Columns.Add(P2_checkbox);
            dataGridView1.Columns.Add(P3_checkbox);
            dataGridView1.Columns.Add(P4_checkbox);
            dataGridView1.Columns.Add(P5_checkbox);
            dataGridView1.Columns.Add(P6_checkbox);
            dataGridView1.Columns.Add(P7_checkbox);
            dataGridView1.Columns.Add(P8_checkbox);
            dataGridView1.Columns.Add(P9_checkbox);
            dataGridView1.Columns.Add(P10_checkbox);
           
            //SqlCommand cmd1 = new SqlCommand("select * from View_1", con);
            //SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
            //DataSet ds1 = new DataSet();
            //da1.Fill(ds1, "Attendance1");
            //dataGridView1.DataSource = ds1.Tables["Attendance1"];
        }

Answers (1)