DevExpress XtraGrid: Make column visible to user - c#

I have a grid with lots of columns (ca. 100). I've written a column selector context menu (which has each letter of the alphabet and then as subitems all the columns beginning with that letter).
When the user clicks in the context menu I want to make the column they have chosen visible to the user (preferably in the middle of the visible grid). I don't want to actually mess with the column order, I just want to make sure a column is visible to the user.
Any ideas?

This can be done using the following approach:
1) set the column's Visible property to true.
2) if you want this column to be in the middle of the grid, set its VisibleIndex property to gridView.VisibleColumnsCount / 2;
3) call the GridView's MakeColumnVisible method to make this column visible to the end user.

Use the GridColumn.VisibleIndex property to change the order in which columns are displayed.
VisibleIndex = -1 hides a column IIRC.

Related

Add a checkbox in a listview (C#)

I'd like to show a listview in a C# application where every row represents a product so the property "view" is set on "detail". One column (the last one) should be a checkbox because it represents if the product is discountinued.
With the checkboxes property set to true, a checkbox appear in the first column so it doesn't work for my application.
How can add the checkbox to the last column? Thank you
The Checkboxes are always associated with the first Column. However you change re-order the display of the Columns.
All you need to do it go to the Columns designer and set the 1st colum's DisplayIndex to the last column's index.
Or do it in code:
listView1.Columns[0].DisplayIndex = listView1.Columns.Count - 1;
listView1.Invalidate();
Note the Invalidate which is necessary to enforce the display of the new layout..

How to make a row select, highlight specific cells

How to make a Row select highlight specific Cells and not all the Row in a Grid View. I have explored all the questions on SOF, but there is nothing is available.
Set the SelectionMode property of the Grid to CellSelect
You need the set the selection mode on the Grid to cell selection.
If you want it to act like a row select but keep a few cells un-highlighted you should use CellSelect as the selection mode. Then register on row selection changed and set the cell.Selected = true; for the ones you want selected, and false for the rest.
I found the solution !! If you want to control the highlight of a row to a certain range of cells, then you need to control the behavior of the cells in question and make them behave differently when the a row is selected.
YourGridviewInstance.GetCellRange(int topRow,int leftColumn,int buttomRow,inr RightColumn)
in other words
YourGridviewInstance.GetCellRange(YourCurrentRow, The column you want to affect,YourCurrentRow, The Same Column you want to affect)

Devexpress Winforms DataGridView: Deactivate "Drag Column Header here to group by that column"-Option

How do I deactivate the function to group by column header, which is shown in top of a datagridview-control by devExpress?
So which option does the control have to deactivate it, something like: controlGroupOption = false?
To hide the group panel, set the GridView.OptionsView.ShowGroupPanel property to False
To hide the group panel text, set the GridView.GroupPanelText property to " " string (a space character).
I suggest you to go though Disabling Grouping section in the XtraGrid documentation.
To prevent an end-user from changing grouping settings, you can use a number of properties.
The GridOptionsView.ShowGroupPanel property specifies the visibility of a group panel. If the panel is invisible, end-users will not be able to group data using drag-and-drop. In this case, the order of the group columns can only be determined by end-users using group row captions.
Disable the column header menu and group panel menu using the GridOptionsMenu.EnableColumnMenu and GridOptionsMenu.EnableGroupPanelMenu properties. Note that you can also customize these menus as described in the Implementing Custom Behavior for Popup Menus topic.
The GridOptionsCustomization.AllowGroup property specifies whether or not end-users can apply data grouping in a View. If this property's value is false, grouping is available only in code. If this property is set to true, end-users can group data if grouping and sorting is enabled for the desired column.
The GridOptionsCustomization.AllowSort property specifies whether or not end-users can apply data sorting. Data cannot be grouped if sorting is disabled.
A column's OptionsColumn.AllowGroup option controls whether or not end-users can apply grouping to that column.
A column's OptionsColumn.AllowSort option determines whether or not end-users can sort rows against a column. As stated above, grouping is only available if a column supports sorting.
A column's OptionsColumn.AllowMove and View's GridOptionsCustomization.AllowColumnMoving options control whether or not end-users can move the column. Since grouping implies moving a column onto a group panel, you can disable grouping just by preventing a column from being moved.
Code snippet to disable grouping for the a column in a view.
gridView1.Columns["fieldName"].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
//
DevExpress.XtraGrid.GridControl gridControl;
DevExpress.XtraGrid.Views.Grid.GridView gridView;
to enable grouping capability
gridView.OptionsView.ShowGroupPanel = true
to disable
gridView.OptionsView.ShowGroupPanel = false

Set the visibility of a column that has been grouped (single column)

I am grouping data in a grid by two different columns.
One of the columns needs to be retained as visible and the other needs to be removed from the grid.
I have set "ShowGroupedColumns" to false as it automatically handles the column chooser etc.
But I cant seem to figure out how to make the one I want to retain visible.
Is there any way, with ShowGroupedColumns set to false that I can have it grouped by column and have the column in the grid too?
Thanks
The same problem have been already discussed in DevExpress Support Center:
Display individual columns, even if they are grouped

DevExpress cascading comboboxes in datagridview

I have a datagridview bound to a datasource, and in each row in the grid there is a category, product, and quantity. I want to filter the products in each row according to the selected category.
I'm using C# and DevExpress. How can I do this?
Please refer to the How to filter a second LookUp column based on a first LookUp column's value article which explains how to implement this feature.
Depending on how You want to filter you can set
gridView1.OptionsCustomization.AllowFilter = true;
This will display an additional filter row in your grid that will allow you to filter all columns by any text you want;
Or you can make sure that gridView1.OptionsCustomization.AllowFilter is set to true. Then there should be little icon on your column header (visible in right top corner when you move cursor over the column header) that will display filter after you click it.

Categories

Resources