Skip to content

Checkbox default value

New Discussion
Watson
Watson asked on Apr 7, 2017 1:07 PM

Hi,

I am adding a CheckBox column to my wingrid at runtime.  How can I make it default to ‘false’ as opposed to the filled in square of ‘null’?  Right now I am looping through each cell and setting it to False.  This is also marking the row as “edited”.  Does anyone know a better way?  Here is my code so far:

 

 

Infragistics.Win.UltraWinGrid.UltraGridColumn completedColumn;

completedColumn = myGrid.DisplayLayout.Bands[0].Columns.Insert(0, “Completed”);

 

completedColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;

foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in myGrid.Rows)

{

row.Cells[“Completed”].Value = false;

}

 

 

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Jan 11, 2008 3:19 PM

     Hi,

        Looping through the rows is certainly not the best way to do it.

        The best way is probably to do it on the data source. What kind of data source are you using? Most data sources, like a DataTable or UltraDataSource let you specify a default value for a column.

        Another way to do it would be to use the InitializeRow event of the grid, rather than looping.

    • 0
      Vijay
      Vijay answered on May 23, 2011 2:33 PM

      Hi,

      I am just googling on Default value for CheckBox Column and found this post .

      If I apply the same thing on InitializeRow event then It will fire the AfterRowUpdate, AfterCellUpdate and Other event.

      I want the same thing without fire the AfterRowUpdate, AfterCellUpdate and other event on InitializeRow event.

      Kindly suggest.

       

      Vijay

      • 0
        Mike Saltzman
        Mike Saltzman answered on May 24, 2011 2:02 PM

        Hi Vijay,

        No matter what event you use, the events will always fire. There is no way around that.

        So you will either need to establish a default value for the field in your data source before binding to the grid.

        Or, you could unhook the events or use the EventManager to disable those events and then loop though the rows.

      • 0
        Vijay
        Vijay answered on May 24, 2011 2:10 PM

        Thankx Mike for your reply.

        I had done the changes using a fake column in my datasource. That particular check boxcolumn is nothing but only show the data entry status to user. If the user save the grid data then checkbox will displayed as Checked, If user enter new row in Grid then checkbox show as Un-checked.

        Thankx for your kind replay.

      • 0
        WDV
        WDV answered on Jul 20, 2016 1:18 PM

        Hi, found this (old) post through Google.

        Using infragistics 15.1, I'm having the same issue and am unable to work out a solution: There are multiple columns defined as Boolean? but the grid should display a checked or an unchecked checkbox, not tristate. Setting a default value on our generic datasource is not desirable.

        In the initializelayout event of the grid, I tried forcing the style of all the affected columns to UltraWinGrid.ColumnStyle.CheckBox. No success.

        I see that column.IsNullable is True, if I change column.Nullable to UltraWinGrid.Nullable.Disallow the value becomes false. However, the visual outcome remains the same.

        Any suggestions?

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jul 20, 2016 3:32 PM

        Hi,

        What, exactly, is the issue you are having?

        The CheckBox in the cell reflects the value of the cell. So the way to "fix" this is to have the value of the cell (and therefore the value of the data source) return a valid value.

        If your cell contains a null or DBNull, then that is not a valid true/false value. If you want the CheckBox to treat a null value as unchecked (as opposed to indeterminate), then you could use a DataFilter that converts null to false and vice versa. Is that what you want? If you do that, then the value of false will always be null in the data source. There's no way for a data filter to determine that the cell was originally null, but got translated to false by the datafilter. So either the cell would change the null to a false the first time it updated, or else you would always have to use null for false, instead of actually using false.

      • 0
        WDV
        WDV answered on Jul 21, 2016 10:28 AM

        Indeed, I'd like to display both false and dbnull as unchecked.

        I'll have a look at the datafilter. The grid is only used to display the values, no editting allowed.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jul 21, 2016 2:58 PM

        Hi,

        I whipped up a quick sample to show you how the DataFilter approach would work. Let me know if you have any questions.

      • 0
        WDV
        WDV answered on Jul 21, 2016 8:47 PM

        I've never used the datafilter before, works great.

        Implementation was a breeze thanks to your sample!

      • 0
        ganesh khare
        ganesh khare answered on Apr 7, 2017 1:07 PM

        Hi Mike,

        I want checkbox is check by default when ultragrid is loaded can we do setting in properties?

    • 0
      ganesh khare
      ganesh khare answered on Feb 14, 2017 2:24 PM

      Hi Mike,

      I have checkbox in a ultragrid and i want to first check by default when grid is loaded  how can i do that please suggest me.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 14, 2017 9:56 PM

        Hi Ganesh, 

        The simplest way would be to bind the grid to a data source where all the values for that column are true. 

        If it's an unbound column, then you can use the DefaultCellValue property on the column and set that to true.

        Or you could use the InitializeRow event to set the value of the checkbox cell to true when e.ReInitialize is false. 

      • 0
        ganesh khare
        ganesh khare answered on Feb 15, 2017 8:44 AM

        Thanks Mike,

        Yes its unbound column but i want to check only one row at the run time. So please can you provide some example.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 15, 2017 2:43 PM

        Then you have to set the value of the cell in that row to true.

        this.ultraGrid1.Rows[0].Cells["My CheckBox Column"].Value = true;

      • 0
        ganesh khare
        ganesh khare answered on Feb 15, 2017 2:58 PM

        I am relay very appreciate with your reply Mike. I have one more question i want to check the chekbox on billingPolicyGroupUltraGrid_AfterRowActivate event and after that i want to call the cell change event is it possible. if yes please provide example.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 15, 2017 3:02 PM

        Setting the CheckBox state in AfterRowActivate is pretty simple: 

        billingPolicyGroupUltraGrid.ActiveRow.Cells["My CheckBox Cell"].Value = true;

        I'm not sure what you mean by "call the cell change event". You can't call an event. That event fires when the contents of a cell in edit mode are changed by the user. So you can't make it fire programmatically. What you would typically do in such a case is move the code from that event into a method. Then call that code from the CellChange event and from anywhere else you want. 

      • 0
        ganesh khare
        ganesh khare answered on Feb 21, 2017 2:57 PM

        Hi Mike, I have facing one problem i Have a ultragrid with checkbox Problem is that when i have check 4 checkbox at coding level it show only 3 is checked 4th checkbox value return false i am not able get all checked box value. My code is that

        1)i have  check 4 checkbox.Its return only 3 is true and 4th checkbox is false

        int i = 0;
        foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in billingPolicyGroupUltraGrid.Rows)
        {

        foreach (Infragistics.Win.UltraWinGrid.UltraGridCell cell in row.Cells)
        {

        if (cell.Column.Key == "SelectToProcess")
        {
        if ((bool)cell.Value)
        {
        //if checked return true
        i++;

        }

        }

        }

        }

        can you provide any other solution to get all checked checkbox value 

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 21, 2017 3:08 PM

        My guess is that you checked the checkbox using the mouse and then you clicked on a toolbar button or some other object that doesn't take focus from the grid. The last cell you changed is therefore still in edit mode and the change has not yet been committed, so the Value property of the cell has not yet been updated with the new value. 

        The easiest solution to that is to call grid.UpdateData to commit all changes to the grid before you start your loop. 

      • 0
        ganesh khare
        ganesh khare answered on Feb 21, 2017 3:23 PM

        Mike Its Working

        Thanks a lot

      • 0
        ganesh khare
        ganesh khare answered on Feb 23, 2017 10:00 AM

        Hi Mike

        when i have select any row in ultragrid then i dont want to selected row backgroung color blue what can i do for that.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 23, 2017 2:31 PM

        Do you mean activate a row or select it? It doesn’t make any sense to select a row and not have any visual indication that the row is selected.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Watson
Favorites
0
Replies
21
Created On
Apr 07, 2017
Last Post
9 years, 5 months ago

Suggested Discussions

Created by

Created on

Apr 7, 2017 1:07 PM

Last activity on

Feb 23, 2026 9:36 AM