الاثنين، 15 يونيو 2015

Filter in RadGridView




        private void txtFilter_TextChanged(object sender, EventArgs e)
        {
            #region MyRegion

            if (!string.IsNullOrEmpty(txtFilter.Text.Trim()))           
                FilterMethod(txtFilter.Text.Trim(), "ItemName");           
            else
                grdvUsersGroups.Columns["ItemName"].FilterDescriptor = null;
            #endregion
        }   

--------------------------------


private void FilterMethod(string text,string colName)
        {
            var filter1 = new FilterDescriptor {Operator = FilterOperator.Contains, Value = text, IsFilterEditor = true};
            for (var i = 0; i < grdvUsersGroups.ColumnCount; i++)
            {
                if (grdvUsersGroups.Columns[colName].DataType == typeof(string))
                    grdvUsersGroups.Columns[colName].FilterDescriptor = filter1;               
            }
            //grdvUsersGroups.TableElement.ScrollToRow(grdvUsersGroups.Rows.First());

        }
------------------------------------------
To Display Users of Groups Only

private void radioAll_CheckStateChanged(object sender, EventArgs e)
        {
            if (sender != null)
            {
                var rdoButton = sender as RadRadioButton;
                if (rdoButton != null && rdoButton.IsChecked)
                    if (rdoButton.Name == "radioUsers")
                    {
                        FilterMethod("2", "isGroup");
                    }
                    else if (rdoButton.Name == "rdioGroups")
                    {
                        FilterMethod("1", "isGroup");
                    }
                    else
                    {
                        grdvUsersGroups.Columns["ItemName"].FilterDescriptor = null;
                        grdvUsersGroups.Columns["isGroup"].FilterDescriptor = null;
                        if (!string.IsNullOrEmpty(txtFilter.Text.Trim()))
                        {
                            FilterMethod(txtFilter.Text.Trim(), "ItemName");
                        }
                    }
            }

        }     

------------------------------
Font is Regular for User but Bold for Group:

private void grdvUsersGroups_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
         if (e.RowElement == null || e.RowElement.RowInfo.Index <= -1) return;
         if (e.RowElement.RowInfo.Cells["GroupId"].Value != null)
         {
             e.RowElement.Font = Convert.ToInt32(e.RowElement.RowInfo.Cells["GroupId"].Value) != 0
                                 ? new Font(Font, FontStyle.Bold)
                                : new Font(Font, FontStyle.Regular);                       
         }
         else e.RowElement.Font = new Font(Font, FontStyle.Regular);

}

ليست هناك تعليقات:

إرسال تعليق