Hi,
I am developing a webform that has a webgrid. The grid is supposed to be able to allow the user to select the text inside the cell. The only problem I have is that some of the cell have also a JS functionality (cellclick) that I need to handle. Using the ReadOnly property for the grid, I am able to select the text inside a cell, but I am not able to fire the CellClick event. Is there any other way to be able to select a text (or part of a text) and also use the fully functionality for a cell?
Regards,
Aurelian
You can manually attach a click event to the grid's table element, and use the srcElement on the event parameter to get the exact cell in question.
-Tony
Tony, can I have a simple example that I can use?
just ignore 37,38,39,40 key code , using return true
if(nextCell != null) { nextCell.activae(); nextCell.beginEdit(); return true; }
Wow, great tip! Thanks for sharing this with everyone.
Let me get this straight:
You want to:
Is that right?
This call: newCell.setSelected(true);
will only set the cell to selected, not the text inside of the editor.
I don't know how to get the editor, but I have a workaround for you that _might_ work.
If you use a WebTextEdit control and set the "SelectionOnFocus" property to "SelectAll" and then apply the editor to each column that you want this behavior on it should select all of the text as soon as you enter edit mode.
To apply a WebTextEdit control to a column do this:
Code:
grid.Bands[0].Columns[0].Type = ColumnType.Custom;
grid.Bands[0].Columns[0].EditorControlID = txtEdit.UniqueID;
Aspx:
<igtbl:UltraGridColumn Type="Custom" EditorControlID="txtEditId">
Hi Tony,
I am using the following code to navigate through cells using arrow keys. When i land on the cell I want the existing text to be selected. I am trying to use the setSelected(true) method but it is not selecting.
function ugrdApplicants_EditKeyDownHandler(gridName, cellId, key){ var grid = igtbl_getGridById(gridName); var cell = igtbl_getCellById(cellId); var row = cell.getRow(); var col = cell.Column; switch(key) { //If Up/Down Key case 38: case 40: if (col.ColumnType != 5) { if (key == 38) var nextRow = row.getPrevRow(); else var nextRow = row.getNextRow(); if(nextRow != null) { cell.endEdit(true); var newCell = nextRow.getCell(cell.Index);
newCell.beginEdit(); newCell.setSelected(true); } } break; //If left/right key case 37: case 39: if (key == 37) var nextCell = cell.getPrevCell(); else var nextCell = cell.getNextCell(); if(nextCell != null) { cell.endEdit(true); newCell.setSelected(true); newCell.beginEdit(); } break; default: break; }
}
I have the following settings on my Grid.
<DisplayLayout AutoGenerateColumns="False" SelectTypeCellDefault="Single" SelectTypeColDefault="Single">
Thank you.
In the code above, you are in effect handling the cell click and/or double click. What you do from inside of that handler is limited only to your imagination. You can highlight (select) cells through the client-side object model which is documented in our help files. You'll want to use the select function off of the cell object. In my code snippet above, I'm calling setValue, just replace that with select
http://help.infragistics.com/Help/NetAdvantage/NET/2007.3/CLR2.0/html/WebGrid_cell_Object_CSOM.html
Also, as an alternate approach, you can set the grid's AllowUpdateDefault property to false, which will prevent the user from entering data. The user will still be able to use other functions of the grid, but will not be able to edit any of the cells.
The readonlymode property of the grid is used to limit functionality (and hence, 'weight') of the grid.
Hope this helps,