How to make a row select, highlight specific cells - c#

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)

Related

How to focus cell in row for adding new record in DataGridView?

How can I programmatically focus cell in WinForms DataGridView shown highlighted on sample below?
I can easily set focus to any cell in rows 0~3 but that cell is in row 4 which looks like "virtual" because dataGridView1.Row(4) does not exist.
Not sure if i have quite got your question but does DataGridView1.NewRowIndex not work for what you want?
I tried DataGridView1.Item(0, DataGridView1.NewRowIndex).Selected = True which seems to do what I think you are trying to achieve.
The code above is on the click event of button 1 and produces the following:
If you want to 'un-select' any currently selected cell first then precede the above with If Not IsNothing(DataGridView1.CurrentCell) Then DataGridView1.CurrentCell.Selected = False, the If Not IsNothing... is to cover the code running where no cell is currently selected.
BTW I don't think you can use .CurrentCell for a cell selected on the new row, but you can use .item

How can I display all text in Cell of GridView

I use GridView in my C# application, and the cell seems too small.
I find the prop of GridView, but I find nothing about it. How can I display all text in Cell?
Under Columns Collection property there is AutoSizeMode under Layout. And use for example DisplayedCells and see for yourself.
For Word Wrap you could set it programmatically like:
// Columns[1] for 2nd column based on your example.
dataGridView.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.true;
But don't set the AutoSizeMode as above or else the columns will still expand.
You could set it also manually under Columns Collection property and under Appearance select Default Cell Style and then set WrapMode to true.

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.

Highlight a row with particular color in datagrid

I have a data grid with multiple rows. My requirement is whenever I select a row it should be highlighted. I have disabled the cell selection by giving Background color same as selection color so user feel cell is not selected.
But how to select a row in data grid and highlight it with some color by changing some property ..i am using the following code to make user feel that the cell is not selected.
dataGridViewCellStyle11.SelectionBackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle11.BackColor = System.Drawing.SystemColors.Window;
A few questions, do your users need to be able to select individual cells? Since you changed the color of the cell select to make it seem like it is not selected, then how do you decide when to highlight the full row?
It sounds like you want to change the SelectionMode property on your DataGridView. If you change it to FullRowSelect then you will highlight your entire row when any cell in the row is selected.
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

Programmatically setting the record pointer in a C# DataGridView

How do I programmatically set the record pointer in a C# DataGridView?
I've tried "DataGridView.Rows[DesiredRowIndex].Selected=true;", and that does not work. All it does is highlight that row within the grid; it doesn not move the record pointer to that row.
To change the active row for the datagrid you need to set the current cell property of the datagrid to a non-hidden non-disabled, non-header cell on the row that you have selected. You'd do this like:
dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow];
Making sure that the cell matches the above criteria. Further information can be found at:
http://msdn.microsoft.com/en-us/library/yc4fsbf5.aspx
Try setting the focus of the DataGrid first . Some thing like this
dataGridView1.Focus();
dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow];
This worked in my case, hope it helps you as well

Categories

Resources