How do I highlight an active row in a Infragistics grid? - c#

I have a row that I activated via code. However, I need it to be highlighted as well, but can't seem to find the correct property to set. How can I do this via C#?

You can change the appearance of the active row through the ActiveRowAppearance

I think the following solution should work for you:
ultraGrid1.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.IndianRed;
ultraGrid1.Rows[0].Activate(); //programatically set active row
ultraGrid1.Selected.Rows.Clear(); //clear your selection of previous row

Related

How to disable Drag from a particular row of a DataGridView in C# and Winforms?

I'm looking for the best way to disable a row of a DataGridView after a successfull Drag&Drop action.
So, I've already dropped the row and marked it as moved using background color.
Now I need to disable further Drag&Drop on the same row. Is this possible without removing the row?
I can de-select a dropped datagridview row but I can't mark it as not "draggable":
dgvToolPosition.Rows[dgvToolPosition.SelectedRows[0].Index].Selected = false;
Is there any possible way to set a property of the row avoiding the insertion of the corresponding index on a List<DataGridViewRowCollection> of already dropped rows?
Shot it the dark, but couldn't you just capture the drop event and check if you've moved it to the same row? I did a quick Google search for that event, this is what I came up with :
https://msdn.microsoft.com/en-us/library/system.windows.forms.dragdropeffects(v=vs.110).aspx
The best way for avoiding the Drag event on a previously dropped row is to check for the unique property of the row that I set on a successfull drop operation (DefaultCellStyle.BackColor):
// Check if a row in the current selection has a gray background color,
// so it can be skipped on Drag&Drop.
foreach(DataGridViewRow selectedRow in dgvToolPosition.SelectedRows)
{
if(selectedRow.DefaultCellStyle.BackColor == FCSCoreGlobal.ColorGray)
return;
}
I know it's not the best way to do it, but until now it's the best trick I've found. I'm still looking for a AllowDrag property on a DataGridViewRow to set to false.

Enabling and disabling of columns in Infragistics UltraGrid

I have an Infragistics grid and I want to disable and enable some columns based upon some requirement. I have read some articles that say to use AllowUpdate = DefaultableBoolean.True but it did not work for me.
I suppose that when you talk of disabled columns you mean disable editing in these columns.
Also you don't specify the language, so I will use C#
UltraGridColumn c = grdWork.DisplayLayout.Bands[0].Columns["YourColumnName"];
c.CellActivation = Activation.NoEdit;
c.CellClickAction = CellClickAction.CellSelect;
The property CellActivation could also be set to Activation.Disabled or Activation.ActivateOnly.
The property CellClickAction allows to set an appropriate selection status for the cell clicked. You could use CellSelect or RowSelect. (This last one, to mimic the behavior of a ListBox)
As usual, the real difficulty is to find the correct property. Then Intellisense will give you a quick and fair explanation of the meaning of these values.
If you just want to show and hide the columns as needed then you can try the following.
UltraGrid myGrid = new UltraGrid();
//Bind to your data here
myGrid.DisplayLayout.Bands[0].Columns["ColumnName"].Hidden = true;

Getting PK value from data grid view

I have a data loaded from database into dataGridView, with effect looking like this:
(in final version I would prefer to hide the PatientID column)
What I'm trying to do, is return value of PatientID when user clicks ANYWHERE in the corresponding row (i.e. user clicks "Doe" and value returned is "2"). Could anyone give me a hint how to do this? I don't think there is valueMember property... I was trying Rowindex but that returns value of number of row counting from the top(D'uh?!)
Also, is there a way for user to highlight whole row when clicking on the single cell?
EDIT: Oh God, I've spent few hours late at night to find this, In the morning I gave up and posted here... just to find answer 5 minutes later:
string test = dataGridView1.Rows[e.RowIndex].Cells["PatientID"].FormattedValue.ToString();
Still, that leaves my second question about highlighting whole row.
If the datagridview is bound to some data source (DataView), you can use DataBoundItem property, for example
DGV.CurrentRow.DataBoundItem["PatientID"]
or
DGV.SelectedRows[0].DataBoundItem["PatientID"]
or
DGVUnderlyingBindingSource.Current["PatientID"]
If the DataGridView is bound to a strongly typed data source (e.g. BindingList) then you can use the above like this:
((PatientType)DGV.CurrentRow.DataBoundItem).PatientID
or
((PatientType)DGV.SelectedRows[0].DataBoundItem).PatientID
or
((PatientType)PatientTypeBindingSource.Current).PatientID
About the second part of the question, set the DataGridView's SelectionMode property to FullRowSelect
EDIT
You can't use the solution from your edit if you hide that column. In order to access the value by using .Cells[idx].FormattedValue that value must be visible. But you can use this one even if you hide the column.
For the second question, set selection mode to FullRowSelect and the complete row will be highlighted when the user clicks on it. You can set this attribute in the designer or code:
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

How do I position a DataGridView to a specific row (so that the selected row is at the bottom)?

As a question similar to this question, I also have an application with a DataGridView on it. I would like to position the rows such that a specific row is at the bottom of the visible part of the list.
This is in response to a button click that moves a row down by one. I want to maintain the selection on the row I'm moving (I already have this part working). If there are lots of rows, the selected row might move below the visible area. I want to scroll down until it's at the bottom of the visible area.
There does not appear to be a LastDisplayedScrollingRowIndex companion to FirstDisplayedScrollingRowIndex.
Any ideas? Thanks.
As my own guess, I think I need to use FirstDisplayedScrollingRowIndex and the number of rows visible in the DataGridView to calculate the new FirstDisplayedScrollingRowIndex. Maybe I just need to find out what the NumberOfVisibleRows property is called?
Found it. DisplayedRowCount:
if (dataGridView.FirstDisplayedScrollingRowIndex + dataGridView.DisplayedRowCount(false) <= selectedRowIndex)
{
dataGridView.FirstDisplayedScrollingRowIndex =
selectedRowIndex - dataGridView.DisplayedRowCount(false) + 1;
}
Code tested and working in my own project.
The DisplayedRowCount method will tell you how many rows are displayed on screen. Set the parameter value to true to include partial rows.
var displayedRows = myDataGridView.DisplayedRowCount(false);

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