Janus 4 GridEx disable rows

3.3k views Asked by At

I have have a Janus 4 GridEx control which includes a checkbox column. I need to be able to disable certain rows (i.e make them non selectable/greyed out) depending the value of a particular column. The data for the grid is loaded from a database.

Any help would be appreciated.

2

There are 2 answers

0
Adel Khayata On

You have to utilize the LoadingRow and SelectionChanged events of the Janus Grid.

This is a sample code: ( Here I'm checking the value of a particular column to be divided by 2)

    private void grdEx_LoadingRow(object sender, Janus.Windows.GridEX.RowLoadEventArgs e)
    {
        if (Convert.ToInt32(e.Row.Cells["ID"].Value) % 2 == 0)
        {
            e.Row.RowStyle = new GridEXFormatStyle(e.Row.Table.RowFormatStyle);
            e.Row.RowStyle.BackColor = Color.Gray;
        }
    }

    private void grdEx_SelectionChanged(object sender, EventArgs e)
    {
        if (Convert.ToInt32(grdEx.GetValue("ID")) % 2 == 0)
        {
            if (grdEx.Row >= 0)
            {
                if (grdEx.Row == grdEx.RowCount - 1)
                    grdEx.Row = grdEx.Row - 1;
                else
                    grdEx.Row = grdEx.Row + 1;
            }
        }
    }
0
Makesh On

Depending on the Checkbox column , just see the sample code:

 private void grdEX1_FormattingRow(object sender, RowLoadEventArgs e)
 {
        if (e.Row.RowIndex > -1 && e.Row.RowIndex < grdEX1.RowCount)
        {
            for (int i = 0; i < grdEX1.RootTable.Columns.Count; i++)
            {
                if (!Convert.ToBoolean(e.Row.Cells["checkboxCol"].Value))//checked So editable
                {
                    e.Row.Cells[i].FormatStyle = new GridEXFormatStyle() { BackColor = Color.LightGray };
                }
                else
                {
                    e.Row.Cells[i].FormatStyle = null;
                }
            }
        }
    }

To prevent the editing if the row is not checked :

private void grdEX1_EditingCell(object sender, EditingCellEventArgs e)
{
     if(!Convert.ToBoolean(grdEX1.GetValue("checkboxCol"))) //not checked 
    {
        e.Cancel = true;
        return;
    }
}