We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Highlight row in disabled grid

Hi,

I'm using your GridControl to show a simple list of objects and I want to highlight the selected row. But I don't want the user to edit in this grid, so I set the Enabled = false for all the cells. If I only set ReadOnly = true, the user can still click in a cell and mark text. I don't want this behaviour.

How is the best way to highlight the selected row in this case.

Thanks in advance,
Kjetil

5 Replies

RA Rajagopal Syncfusion Team July 27, 2007 08:33 PM UTC

Hi Kjetil,

To make the whole row selected by clicking on any of the cells, add the code below. This will work fine even for disabled cells.

this.gridControl1.ListBoxSelectionMode = SelectionMode.One;

Let us know if you have any other questions.
Regards,
Rajagopal


KJ Kjetil July 30, 2007 07:33 AM UTC

Hi and thanks for a prompt reply!

This information helps. So by setting Enabled = false for the whole table, and setting the SelectionMode to One, the grid looks and behaves the way I want.

But since all cells are disabled, I can't use .CurrentCell. What is the best way to find the row that is selected. It looks like I can find the information under GridControl.Model.SelectedRanges. Is that what I should use?


RA Rajagopal Syncfusion Team July 30, 2007 05:29 PM UTC

Hi Kjetil,

You could determine the clicked row using the grid.PointToRowCol() method in the MouseDown event of the grid.

int row, col;
void gridControl1_MouseDown(object sender, MouseEventArgs e)
{
Point pt = new Point(e.X, e.Y);
this.gridControl1.PointToRowCol(pt, out row, out col);
Console.WriteLine("RowIndex: {0}", row);
}

Regards,
Rajagopal


KJ Kjetil August 1, 2007 05:31 AM UTC

Hi Rajogopal,

Well I use the CellClick event, and there I can use the e.RowIndex to find the row clicked. This works even if all the cells are disabled. The problem however is when the user clicks a button outside the grid to edit the selected record. Then I want to find the selected row.


HA haneefm Syncfusion Team August 1, 2007 08:52 PM UTC

Hi Kjetil,

In both GridControl and GridDataBoundGrid classes, there is a member Selections which you can use to access exactly what cells are selected in the grid. This Selections class has a GetSelectedRows method that returns an array of ranges that are selected row ranges. You can iterate through this array to get all the ranges. So, to get the row index of this selected row , you can use code such as:

GridRangeInfoList list = this.gridDataBoundGrid1.Model.Selections.GetSelectedRows(true, true);
foreach (GridRangeInfo range in list)
Console.WriteLine("RowIndex : " + range.Top);

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon