2
Answers

How to customize datagridview column and event on column

Andy Wij

Andy Wij

13y
2.1k
1
Hello all, I've a datagridview bind with a datatable on runtime..
Let say the datatable contain column like this,

Request_No, Item_Code, Qty, Qty_In, Remark..

If I bind the datatable to datagrid then on datagrid will appears 5 columns.

My question is can I make some column disappears and how can I put some code when column1 on keypress event?

Thanks.
Answers (2)
0
Andy Wij
NA 26 27.1k 13y
Hi Nayak, thanks for the reply.. I got it now.. but how about event on grid.. example I want when the user press 'F3' keys on column2(only on column2) then another form will appears, where I must put the event handler?
0
Satyapriya Nayak
NA 53k 8m 13y
Hi Andy,

To disappears some column in a dataGridView
dataGridView1.Columns[0].Visible = false; 1st column



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Update_delete_datagridview
{
    public partial class Form1 : Form
    {
       OleDbDataAdapter oledbda;
       OleDbCommandBuilder olcb;
       DataTable dataTable;
       BindingSource bindingSource;
       string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
       string str;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            OleDbConnection con = new OleDbConnection(ConnectionString);
            con.Open();
            str = "SELECT * FROM student";
         
            oledbda = new OleDbDataAdapter(str, con);
            olcb = new OleDbCommandBuilder(oledbda);
            dataTable = new DataTable();
            oledbda.Fill(dataTable);
            con.Close();
            bindingSource = new BindingSource();
            bindingSource.DataSource = dataTable;
            dataGridView1.DataSource = bindingSource;
            dataGridView1.Columns[0].Visible = false;
        }

        private void btnaddupdate_Click(object sender, EventArgs e)
        {
            try
            {
                oledbda.Update(dataTable);
            }
            catch (Exception exceptionObj)
            {
                MessageBox.Show(exceptionObj.Message.ToString());
            }
            MessageBox.Show("Records updated");

        }
      
    }
}


Thanks