user8920029
user8920029

Reputation:

Devexpress ActiveBandedGridView selected row?

In this method, I need to write additional condition when if the row is not selected only then make back color thistle. How can I do it?

private void docsActiveBandedGridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{        
    DataRow dtrow = docsActiveBandedGridView.GetDataRow(e.RowHandle);

    if (dtrow != null && executeDocIDs.Contains(decimal.Parse(dtrow["ID"].ToString())))
         e.Appearance.BackColor = Color.Thistle;
}

Upvotes: 1

Views: 352

Answers (2)

Niranjan Singh
Niranjan Singh

Reputation: 18290

you can implement your own row style using the GridView.RowCellStyle event.

private void docsActiveBandedGridView_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
    //If row is selected or focused then do nothing   
     if(view.IsRowSelected(e.RowHandle) || view.FocusedRowHandle == e.RowHandle)
         return;   
     DataRow dtrow = docsActiveBandedGridView.GetDataRow(e.RowHandle);

     if (dtrow != null && executeDocIDs.Contains(decimal.Parse(dtrow["ID"].ToString())))
        e.Appearance.BackColor = Color.Thistle;
 }

To prevent selected or focused row to be painted in your existing code just check for the selected or focused row and do not forget to set e.Handled= true :

private void docsActiveBandedGridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{  
    //If row is selected or focused then do nothing   
    if(view.IsRowSelected(e.RowHandle) || view.FocusedRowHandle == e.RowHandle)
      return;   
    DataRow dtrow = docsActiveBandedGridView.GetDataRow(e.RowHandle);

    if (dtrow != null && executeDocIDs.Contains(decimal.Parse(dtrow["ID"].ToString())))
         e.Appearance.BackColor = Color.Thistle;
    e.Handled = true;  //Do not forget to set Handled property to true to know the grid that you handled painting of the grid cell

}

References:
How to customize the FocusedRow and SelectedRow appearance in the GridView
GridView Color Selected Rows
Focused Row Appearance

Upvotes: 1

Hambone
Hambone

Reputation: 16397

This should tell you if the row is selected or not:

docsActiveBandedGridView.GetSelectedRows().Contains(e.RowHandle)

If you don't have multi-select enabled (docsActiveBandedGridView.OptionsSelection.MultiSelect = false), then it might actually be better to used the focused row handle, knowing there will never be more than a single row highlighted:

docsActiveBandedGridView.FocusedRowHandle == e.RowHandle

Upvotes: 0

Related Questions