Add a checkbox in a listview (C#) - 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..

Related

DataGridView column shifts after rebinding

I add a button column through the code to the datagridview after assigning the datasource, it shows correctly after loading. then
Add a new row and save it to the database
Retrieve the data from the database
Populate a datatable and assign it to the datasource of the datagridview
For some reason, the button column shifts from the last to second column? Why would that happen?
Because you generating columns automatically, sure you have DataGridView.AutoGenerateColumns = true
After you change DataSource all generated columns are removed and generated again.
But column added manually stay after generated columns was removed and index of manually added column become 0 or 1.
Then again generated columns added after manually added columns
For solution you can add all columns you need manually in the order you need and set DataGridView.AutoGenerateColumns = false
Or change move button column to the place you want manually every time new DataSource is added

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.

Multi Checkbox columns in Jqgrid

I have jqgrid with 4 columns each with checkboxes format, I need to get All the checkboxes values selected and unselected values based on Column Names.Is it possible?
Updated : Grid Image
The demo from the answer shows how to add custom button in the column header of jqGrid. In the click event handler you can enumerate all rows of the grid and set the column contain to true or '1' depend on the way how you defined the column. In the way you can implement your requirements.

DevExpress XtraGrid: Make column visible to user

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.

DataGridView control scrolls to top when a property changed

On a Windows Form I have a DataGridView control with records that is filled by a data source (data binding). Each record presents a data object.
Not all the rows are displaying: only the first 10 for example. So the user can scroll down to see the another records. Nothing special about this.
But when a user clicks on a row after scrolling, a data property of the object of row is changing and this refreshes the DataGridViewand - it "scrolls" to top of datagrid (maybe the whole DataGridView is refreshing). This is not desirable.
How can I keep the current scroll position during a record update?
You can use the DataGridView's FirstDisplayedScrollingRowIndex property.
It gets/sets the index of the first row displayed on your DGV.
Use it like this:
int rowIndex = dataGridView.FirstDisplayedScrollingRowIndex;
// Refresh your DGV.
dataGridView.FirstDisplayedScrollingRowIndex = rowIndex;
Of course this won't work quite right if sort or add/remove rows to your DGV (you did say you were updating so maybe you're OK).

Categories

Resources