5

I would like certain rows in an Ultragrid to be disabled depending on a boolean Sync property in the row. I have thought of two different solutions but neither have worked out.

1) Databind the Sync property to the Activation property of the row. Is this possible?

2) In an event such as the InitializeRow event of the grid find out what the Sync property is and disable the row if it is set to true. This method works apart from if some more rows are then added to the grid and the grid is then saved, the data reorders itself so that the disabled row isn't containing the right data. Therefore I need a way of knowing when this happens so that I can go through and disable the right rows again afterwards.

private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
    e.Row.Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
    if (e.Row.Cells[grdBoundGrip.DisplayLayout.Bands[0].Columns["Sync"]].Value != null && (bool)e.Row.Cells[grdBoundGrip.DisplayLayout.Bands[0].Columns["Sync"]].Value)
            e.Row.Activation = Infragistics.Win.UltraWinGrid.Activation.Disabled;
}
Jim
  • 1,333
  • 1
  • 11
  • 15
  • 2
    Could you show the code in the InitializeRow event? – Steve Nov 06 '12 at 21:02
  • Hi Steve, I've added the code above which works fine. The problem is that after clicking Save there is some code which updates and changes the order of the dataitems and unfortunately this does not trigger the InitializeRow event again. – Jim Nov 07 '12 at 11:18
  • The docs for [InitializeRow](http://www.infragistics.com/help/topic/5CCF90C4-EEF6-4F4D-A979-B6F505F93318) explain that this event should be called also if you change the values of a single cell. So there is something after the save command that prevents this event to fire. Again, the code after the save command could be of help. – Steve Nov 07 '12 at 11:26
  • @Jim If reordering of the rows doesn't actually change any of the values within the rows then it is expected that InitializeRow doesn't fire. If all you are doing is changing the order in the collection and that determines if a row should be able to be activated, then I would recommend adding a property/column to the list item that the grid is bound to that can be used for tracking so that InitializeRow will fire when the property changes – alhalama Nov 07 '12 at 14:46
  • 1
    In addition call after save to [UltraWinGrid.Refresh](http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.2~Infragistics.Win.UltraWinGrid.UltraGridRow~Refresh(RefreshRow).html) with parameter RefreshRow.FireInitializeRow – Algirdas Dec 21 '12 at 17:53

1 Answers1

5

You can also write it in your own function. I hope below solution might help you.

Create a windows form "test".. and drag/drop an "ultragird" in that windows form as shown below.. enter image description here

create a form load function "test_Load".. and try below code.. your rows with sync "false" is disabled..

   private void test_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Address", typeof(string));
        dt.Columns.Add("Sync", typeof(string));
        dt.Rows.Add(new object[] {"John","United States","False" });
        dt.Rows.Add(new object[] { "Xing", "China", "True" });
        dt.Rows.Add(new object[] { "Ram", "Nepal", "True" });
        dt.Rows.Add(new object[] { "Germany", "Thomas", "False" });
        dt.Rows.Add(new object[] { "Pedrik", "Russia", "True" });

        ultraGrid1.DataSource = dt;
        ultraGrid1.DataBind();

        DisableRowsWithSyncOff(dt.Rows.Count);

    }
    private void DisableRowsWithSyncOff(int _rowcount)
    {
        for (int i = 0; i < _rowcount; i++)
        {                
            if (!Convert.ToBoolean(ultraGrid1.Rows[i].Cells["Sync"].Value.ToString()))
            {                    
                ultraGrid1.Rows[i].Activation = Infragistics.Win.UltraWinGrid.Activation.Disabled;
            }
        }
    }
Sagar Dev Timilsina
  • 1,310
  • 15
  • 32