Results 1 to 3 of 3

Thread: Putting Active or Inactive in a datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2017

    Putting Active or Inactive in a datagridview

    I have a query in which the last column throws me 0 or 1 I want the datagridview to show me Active or Inactive instead of 0 and 1. but I do not know how to do it.

    Thanks in advance

  2. #2
    Join Date
    Sep 2005
    Modesto, Ca.

    Re: Putting Active or Inactive in a datagridview

    You can set the DataGridView column type to DataGridViewCheckBoxColumn. Set the dgv column Header to "Active". Then if the row has a 0 in that column it will be UnChecked, if it has a 1 it will be Checked.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: Putting Active or Inactive in a datagridview

    Just note that you cannot change a column type after it is created. If you want a check box column for data that is not Boolean then you need to create the column yourself first and set its DataPropertyName property to the name of the column you want to bind to. If you follow the CodeBank link in my signature below, you'll find a thread that demonstrates how to add a combo box column that does much the same thing. You will likely also have to explicitly set the TrueValue and FalseValue properties of the column to 1 and 0 respectively.

    The alternative would be to change your SQL code to actually return Boolean values, whatever they may be for your database. In that case, a DataTable you populate using that query will already contain Boolean data and binding will generate a check box column by default.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width