This is a migrated thread and some comments may be shown as answers.

Find a cell's corresponding column

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 31 May 2013, 12:58 PM
Hello,

Is there a way to know for which column a data cell is related to. Because I have to save a row, then put the next row in edit mode and give the focus to the cell which is in the same column than it was in the last selection. From now I almost made it but I can't find anyway to find the column index of the current selected cell.

Thanks 
Pierre
 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Jun 2013, 08:14 AM
Hi Pierre,

This is an example i have tried,it shows the selected cell's column,please check if this helps you.

ASPX:
<asp:Panel ID="ConfiguratorPanel1" runat="server" Style="overflow: hidden; margin-bottom: 15px;">
           <div id="cellSelectedEvents" style="width: 47%; padding: 8px; float: left; height: 100px;
               overflow: auto; border: 1px solid #ccc;">
           </div>
       </asp:Panel>
       <asp:ScriptManager ID="ScriptManager1" runat="server">
       </asp:ScriptManager>
       <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" GridLines="None">
           <MasterTableView ClientDataKeyNames="CustomerID">
           </MasterTableView>
           <ClientSettings AllowKeyboardNavigation="true">
               <ClientEvents OnCellSelected="cellSelected"></ClientEvents>
               <Selecting CellSelectionMode="MultiColumn"></Selecting>
           </ClientSettings>
       </telerik:RadGrid>

JAVASCRIPT:
<script type="text/javascript">
    function cellSelected(sender, args)
 {
  var columnName = args.get_column().get_uniqueName();
  var customer = args.get_gridDataItem().getDataKeyValue("CustomerID")
  var cellInfo = "Cell: " + columnName + " for " + customer + " <b>selected</b><br/>";
  $get("cellSelectedEvents").innerHTML += cellInfo;
 }    
</script>

Thanks
Princy
0
Pierre
Top achievements
Rank 1
answered on 03 Jun 2013, 01:40 PM
your example works fine on the mouse click but I can't get the column name of the focus cell with it because the OnCellSelected event is not fired when the focus change. Is there any event that fires by the RadGrid relative to focus change ?
0
Princy
Top achievements
Rank 2
answered on 04 Jun 2013, 07:37 AM
Hi,

Please try the following code snippet.
In ItemCreated.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
  GridDataItem gd=(GridDataItem)e.Item;
  foreach (TableCell cell1 in gd.Cells)
        {
            int index = gd.ItemIndex;
            cell1.Attributes.Add("OnClick", "OnFocus('" + index + "','" + cell1.ClientID + "')");
        }
    }
}

JAVACRIPT:
<script type="text/javascript">
  function OnFocus(index)
 {
   alert(index);
 }
</script>

Thanks
Princy
Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Pierre
Top achievements
Rank 1
Share this question
or