I am using a devexpress grid and i don't want to have any footer or group summary for string columns. The user can modify the formula used for the footer summary by accessing the footer menu. I want this menu to be disabled for string columns, since the provided summaries do not make sense for string columns. Any ideas?
For all those interested in the solution:
Handle the ShowGridMenu event of the grid:
private void MainView_ShowGridMenu(object sender, GridMenuEventArgs e)
{
Column col;
if (e.MenuType == GridMenuType.Summary && e.HitInfo.Column != null && e.HitInfo.Column.ColumnType == typeof(string))
{
e.Allow = false
}
}
Related
Iam using syncfusion SFListview in my xamarin forms app. I implemented multiselect of listview cell from https://help.syncfusion.com/xamarin/sflistview/selection?cs-save-lang=1&cs-lang=xaml.It works fine.But the problem iam facing is everytime we need to hold the itemcell for selection. Is it possible for multiselect that hold only for first cell and tap for all other cell?
Is it possible for multiselect that hold only for first cell and tap for all other cell?
Sure can do that.If you want multiselect items,I guess that next steps will do some tasks about multiselect items.The picture below may look like the one you want.
You can look at the content of this chapter in the share link, and the sample code it provides.
Solution One:(Generally acceptable)
If the project doesn't mind adding a control button outside, then this will be the quickest and easiest way.That is to add a ToolbarItems in the NavigationPage, use it to control whether you can click multiple selections without jumping to the next page.
Add ToolbarItems :
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="ToolbarItemsButton" Text="MultipleSelect" Clicked="Edit_Clicked"/>
</ContentPage.ToolbarItems>
<sync:SfListView x:Name="listView"
SelectionGesture="Hold"
SelectionMode="Multiple"
ItemTapped="ListView_ItemTapped"
SelectionBackgroundColor="Transparent"
IsStickyHeader="True" ItemSize="70">
...
In ContentPage ,add Flag to judge SelectionMode of ListView.
int flag = 0;
private void Edit_Clicked(object sender, EventArgs e)
{
if(0 == flag)
{
listView.SelectionGesture = TouchGesture.Tap;
ToolbarItemsButton.Text = "Done";
flag = 1;
}
else
{
ToolbarItemsButton.Text = "MultipleSelect";
listView.SelectionGesture = TouchGesture.Hold;
flag = 0;
}
}
Can judge when you can switch to the next page.
private void ListView_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
if(0 == flag)
{
Navigation.PushAsync(new ContentPage());
}
}
Solution Two:(Recommended)
SfListView has a method is ItemHolding.Not using another button also can exchange the SelectionMode.
Xaml code different is adding this method of SfListView.
<sync:SfListView x:Name="listView"
SelectionGesture="Hold"
SelectionMode="Multiple"
ItemTapped="ListView_ItemTapped"
SelectionBackgroundColor="Transparent"
ItemHolding="ListView_ItemHolding" // ItemHolding
IsStickyHeader="True" ItemSize="70">
When OnHolding can do something here:
private void ListView_ItemHolding(object sender, ItemHoldingEventArgs e)
{
if (0 == flag)
{
listView.SelectionGesture = TouchGesture.Tap;
ToolbarItemsButton.Text = "Done";
flag = 1;
}
else
{
listView.SelectionGesture = TouchGesture.Hold;
ToolbarItemsButton.Text = "MultipleSelect";
flag = 0;
}
}
Judge when you can switch to the next page.
private void ListView_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
if(0 == flag)
{
Navigation.PushAsync(new ContentPage());
}
}
Solution Three:(Not recommended here)
Generally, for the multiple selection of the cell of the listview, we will process the template of the custom cell, such as adding a button in the template. When clicking, the item can be marked as selected, and the UI of the item can also be customized as The style when selected.
Starting from WinForms Data Grid v14.2 by enabling the GridOptionsMenu.ShowConditionalFormattingItem property, the Conditional Formatting feature becomes available.
By doing a right click on any column header, the Conditional Formatting menu item is showed up, allowing end-users to apply conditional formatting to grid columns.
My question is that is it possible to disable the feature for a specific column? I'm thinking of having the menu item grayed out, or simply not having it (by hiding it somehow) in the list of items.
I'm aware of the fact that the cells of a specific column can be formatted by the conditional formattings put on other columns by applying the formatting to the entire row. But, my goal is only to make sure the user can not access the functionality for a specific column.
You can remove the corresponding menu-item using the GridView.PopupMenuShowing event:
using System.Windows.Forms;
using DevExpress.XtraGrid.Localization;
using DevExpress.XtraGrid.Menu;
using DevExpress.XtraGrid.Views.Grid;
namespace WindowsFormsApplication2 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
gridView1.PopupMenuShowing += gridView1_PopupMenuShowing;
}
void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
var columnMenu = e.Menu as GridViewColumnMenu;
if(columnMenu != null && columnMenu.Column == this.gridColumn1) {
var conditionalFormattingItem = e.Menu.Items.FirstOrDefault(x => object.Equals(x.Tag, GridStringId.MenuColumnConditionalFormatting));
if(conditionalFormattingItem != null)
conditionalFormattingItem.Visible = false;
}
}
}
}
I'm using ASPxTrrList control from Devexpress and I want to hide delete button (or any column) in some nodes depending on specific condition.
I tried (HtmlRowPrepared) event but I couldn't locate the column I want, it looks like its index changes depending on the node level.
Any way to do this ?
I solved it using this code:
protected void MyTree_HtmlCommandCellPrepared(object sender, TreeListHtmlCommandCellEventArgs e)
{
var node = MyTree.GetAllNodes().SingleOrDefault(k => k.Key == e.NodeKey);
if (node != null && anyCondition)
e.Cell.Visible = false;
}
I'm using only one command button, so I didn't try to hide specific button.
This problem has bugged me for several years and maybe someone here knows a simple solution, since I just ran into it again.
QUESTION: Is there any way to get the XtraGrid to "forget" the current focused row index before a new (different) datasource is assigned to the grid?
BACKGROUND
We use the XtraGrid as a kind of controller for what is displayed in another panel of a multipane Winform.
Now imagine a hypothetical scenario where the datasource of the XtraGrid keeps changing according to menu selections. Menu item 1 populates the grid with a list of today's entrees in the cafeteria: Id, Name. Menu item 2 populates the grid with a list of Customers the user must phone that day: ID, Name. Important thing is that these are separate distinct datasources, and the grid's datasource is being assigned and reassigned.
CRITICAL FACT FOR THIS QUESTION:
We want the grid's FocusedRowChanged event to be the single place where we trap the user's selection in the controller grid. We are a "no spaghetti code" shop. FocusedRowChanged is better than a click event because it handles keyboard navigation too. The row with the focus contains the ID of the detail record we need to fetch from the database for display in Panel #2. This works--most of the time.
Here's how it doesn't work: let's say that on a given day, the list of customers the user must contact contains only one row. So the first (and only) row in the grid is the focused row. Now let's say that the user goes up to the menu and selects the menu item to display the day's cafeteria entrees. When the user clicks on the first item in the Entrees list, the FocusedRowChanged event does NOT fire because the grid has retained a memory of the focused row index from the previous datasource. The focused row index has not changed. And thus the user's selection doesn't trigger anything.
I tried to get DevExpress to offer a second more row-object-oriented mode (as distinct from row-index-oriented approach) whereby each row in the grid would have a GUID, and the FocusedRowChanged event would fire whenever the GUID of the currently focused row differed from the GUID of the previously focused row, regardless of whether the focused row index happened to be the same. This would allow dynamic changes of datasource and enable the desired behavior. But they demurred.
So I'll ask my question again, Is there any way to get the XtraGrid to "forget" the current focused row index before a new datasource is assigned to the grid?
Tim, I had the exact same problem when the grid only had one row of data in it and then changed data sources. I solved it by setting the gridview.FocusedRowHandle = -1 after setting the new datasource.
In a similar situation, I am subscribing to the
FocusedRowObjectChanged
event (using DevExpress 16.1).
I think that the best solution to this problem is to create a new GridView object and override its DoChangeFocusedRowInternal method. Below you will find the default implementation of this method. All you need to do is to change the marked row just as your needs dictate. Also, take a look at the How to create a GridView descendant class and register it for design-time use article, it contains some useful information.
public class MyGridView : GridView {
protected override void DoChangeFocusedRowInternal(int newRowHandle, bool updateCurrentRow) {
if(this.lockFocusedRowChange != 0) return;
if(!IsValidRowHandle(newRowHandle))
newRowHandle = DevExpress.Data.DataController.InvalidRow;
if(FocusedRowHandle == newRowHandle) return; // <<<<<<
int currentRowHandle = FocusedRowHandle;
BeginLockFocusedRowChange();
try {
DoChangeFocusedRow(FocusedRowHandle, newRowHandle, updateCurrentRow);
}
finally {
EndLockFocusedRowChange();
}
RaiseFocusedRowChanged(currentRowHandle, newRowHandle);
}
}
UPDATE
My code:
namespace MyXtraGrid {
public class MyGridControl : GridControl {
protected override BaseView CreateDefaultView() {
return CreateView("MyGridView");
}
protected override void RegisterAvailableViewsCore(InfoCollection collection) {
base.RegisterAvailableViewsCore(collection);
collection.Add(new MyGridViewInfoRegistrator());
}
}
public class MyGridViewInfoRegistrator : GridInfoRegistrator {
public override string ViewName { get { return "MyGridView"; } }
public override BaseView CreateView(GridControl grid) {
return new MyGridView(grid as GridControl);
}
}
public class MyGridView : GridView {
public MyGridView(GridControl ownerGrid) : base(ownerGrid) { }
public MyGridView() { }
protected virtual bool RowEqual(int focusedRowHandle, int newRowHandle) {
if(IsDesignMode)
return focusedRowHandle == newRowHandle;
DataRow row1 = GetDataRow(focusedRowHandle);
DataRow row2 = GetDataRow(newRowHandle);
return row1 == row2;
}
protected override void DoChangeFocusedRowInternal(int newRowHandle, bool updateCurrentRow) {
if(this.lockFocusedRowChange != 0) return;
if(!IsValidRowHandle(newRowHandle))
newRowHandle = DevExpress.Data.DataController.InvalidRow;
if(RowEqual(FocusedRowHandle, newRowHandle))
return;
int currentRowHandle = FocusedRowHandle;
BeginLockFocusedRowChange();
try {
DoChangeFocusedRow(FocusedRowHandle, newRowHandle, updateCurrentRow);
}
finally {
EndLockFocusedRowChange();
}
RaiseFocusedRowChanged(currentRowHandle, newRowHandle);
}
}
}
You can subscribe on the DataSourceChanged event which will fire when Data source changes (you guessed it!) so then you can get using GetFocusedObject() the object and display the relevant items for the other grid...
I have a flex data grid. It contains two column Maths Mark and English Mark. If Math Mark >English Mark for any row then it will set that particular row color as Green.Can you pls suggest me how to do that?
Hi here is your answer but in this i have used AdvancedDataGrid
I have done some thing like that but in my case color was also coming from data also but it will help you.
You have to override the Datagrid and override drawRowBackground method
public class CustomDataGrid extends AdvancedDataGrid
{
protected override function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void{
var XMLdata:XML=rowNumberToData(dataIndex) as XML;
if(XMLdata!=null){
if(XMLdata.attribute(Constants.col) != undefined && XMLdata.attribute(Constants.col) != ""){
color=XMLdata.attribute(Constants.col);
}else{
color=0xFFFFFF;
}
}
super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);
}
}
By this you can get any data from the row and according to it give the color.
more at this link Flex Advanced Datagrid Condition Row Background Color