Windows Develop Bookmark and Share   
 index > Windows Forms General > DATAGRIDVIEW COLUMN CHECK BOX
 

DATAGRIDVIEW COLUMN CHECK BOX

hai my friends

i have a from in c# frmusers,datagridview dgusers connected to oracle manully loading to dgusers

private void frmusers_Load(object sender, EventArgs e)

{

mysrch();

}

public void mysrch()

{

DataSet dsusers = new DataSet();

myqry1 = "SELECT USER_ID,USER_NAME,USER_ADDR,USER_STATUS FROM USERS WHERE " + lblsrch.Text + " LIKE'%" + textBox1.Text + "%'ORDER BY USER_ID";

OracleCommand mycom = new OracleCommand(myqry1, cn);

try

{

cn.Open();

OracleDataAdapter mysed = new OracleDataAdapter(mycom);

mysed.Fill(dsusers);

cn.Close();

dgusers.DataSource = dsusers.Tables[0];

dgusers.Columns[0].Width = 75;

dgusers.Columns[1].Width = 300;

dgusers.Columns[2].Width = 300;


dgusers.Columns[3].Width = 25;


dgusers.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;

dgusers.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;

dgusers.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;

dgusers.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;

dgusers.RowsDefaultCellStyle.SelectionBackColor = System.Drawing.Color.DarkBlue;

}

catch (Exception Ex)

{

MessageBox.Show("ERROR MESSAGE USERS 001");

}

finally

{

cn.Close();

}

loading data to my from successfully( I CAN SEE THAT DATA WHEN FORM LOADING)

what i need my fourth field of my table(users) contains USER STATUS (Y/N)

IN MY GRIDVIEW DGUSERS I NEED FOURTH COLUMN AS A CHECK BOX IF Y IT SHOULD SHOW CHECKED,
AND IF N IT SHOULD SHOW UNCHECKED(NOW IT IS SHOWING Y/N IN CELL OF FOURTH COLUMN)

USERS_STATUS VARCHAR2(1);

HOW I CAN REWRITE MY ABOVE CODE FOR THAT


REGARDS

SADIQUE

hot n thought  Tuesday, February 03, 2009 5:21 PM

Sadique,

Add DatagridviewCheckbox column before assigning datasource to datagridview and set the DataPropertyName of Datagridviewcheckbox column to "USER_STATUS".

you can do it like,

 DataGridViewCheckBoxColumn dgvchk = new DataGridViewCheckBoxColumn();
            dgvchk.DataPropertyName = "USER_STATUS";
            dgvchk.TrueValue = "Y";
            dgvchk.FalseValue = "N";
            dgusers.Columns.Add(dgvchk);
Hope this will help.

NareshG  Tuesday, June 02, 2009 6:24 AM

You can use google to search for other answers

Custom Search

More Threads

• Open a file using default application
• Best Practices Disposing under inherited controls
• To stop the form activated event to fire after closing a MessageBox on the same form.
• How to fire particular Event from FormClosing
• How to delete copy of ListViewItem
• Application Architecture Question
• error during runtime of usercontrol
• how to insert date value into oracle using vb.net
• Buttons (& other controls) and KeyPress
• ControlPaint.DrawReversibleLine