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

Cell value on double click row

Hi!

How to get value from specific row in gridgroupingcontrol when user makes double click on row? Is it possible?

I had tried with this:

 private void gridKumulativno_TableControlCellDoubleClick(object sender, GridTableControlCellClickEventArgs e)
        {
            Console.WriteLine(SelektiraniZapis(grid, "IDVozilo").ToString());
         }  

 private object SelektiraniZapis(string nazivPolja)
        {
            object o = null;

            if (grid.Table.CurrentRecord != null)
            {
                Record r = grid.Table.CurrentRecord;
                int col = grid.TableControl.CurrentCell.ColIndex;
                o = r.GetValue(grid.TableDescriptor.Fields[nazivPolja]);
            }

            return o;
        }

But nothing happens.

3 Replies

AR Arulpriya Ramalingam Syncfusion Team March 7, 2017 10:32 AM UTC

Hi Josip,

Thanks for your interest in Syncfusion products.

The recommended way to get the current record value onTableControlCellDoubleClickevent is by getting the style of the current cell usingGetTableViewStyleInfo()methodby passing theRowIndexandColumnIndexof the clicked cell. Please make use of the below code and sample,

Code Snippet

//Event Triggering

this.gridGroupingControl1.TableControlCellDoubleClick += GridGroupingControl1_TableControlCellDoubleClick;

//Event Customization
privatevoidGridGroupingControl1_TableControlCellDoubleClick(objectsender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellClickEventArgse)
{
//To pass the column index and row index of current record
intcolumnIndex = e.Inner.ColIndex;
introwIndex = e.Inner.RowIndex;
Console.WriteLine(GetRecordValue(rowIndex, columnIndex));

}

//To Get the cell value of current record
privatestringGetRecordValue(introwIndex,intcolumnIndex)
{
stringcellValue =string.Empty;
//To get the style of current cell
GridTableCellStyleInfostyle =this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(rowIndex, columnIndex);
if(style.TableCellIdentity !=null&& (style.TableCellIdentity.TableCellType ==GridTableCellType.RecordFieldCell
|| style.TableCellIdentity.TableCellType ==GridTableCellType.AlternateRecordFieldCell))
{
Recordrecord = style.TableCellIdentity.DisplayElement.GetRecord();
//To get the cell value of current cell
cellValue = record.GetValue(style.TableCellIdentity.Column.Name).ToString();
}
returncellValue;

}

Screenshot

Sample Link

http://www.syncfusion.com/downloads/support/forum/129237/ze/CellValue_on_DoubleClick-1221361787

Regards,

Arulpriya



JO Josip March 7, 2017 07:54 PM UTC

Thanks a lot! Very useful example.

In my case I have grid with 5 columns. Last column is not visible to user but I want to get value from this column. Is it possible?


AR Arulpriya Ramalingam Syncfusion Team March 8, 2017 07:30 AM UTC

Hi Josip, 

  

Thanks for your update. 

  

The hidden column’s record cell value can also be retrieved by passing the hidden column name in the Record.GetValue(“HiddenColumnName”) method. In the below sample, Date column is in hidden mode and value can be retrieved by double clicking on a record 

 

Code Snippet 

  

//Event Triggering 

this.gridGroupingControl1.TableControlCellDoubleClick += GridGroupingControl1_TableControlCellDoubleClick; 

//Event Customization 
private void GridGroupingControl1_TableControlCellDoubleClick(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellClickEventArgs e) 
{ 
    //To pass the column index and row index of current record 
    int columnIndex = e.Inner.ColIndex; 
    int rowIndex = e.Inner.RowIndex; 
    //Console.WriteLine(GetRecordValue(rowIndex, columnIndex)); 
    MessageBox.Show(GetRecordValue(rowIndex, columnIndex)); 

} 

//To Get the cell value of current record 
private string GetRecordValue(int rowIndex, int columnIndex) 
{ 
    string cellValue = string.Empty; 
    //To get the style of current cell 
    GridTableCellStyleInfo style = this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(rowIndex, columnIndex); 
    if (style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell 
        || style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell) 
    { 
        Record record = style.TableCellIdentity.DisplayElement.GetRecord(); 
        //To get the cell value of current cell 
        cellValue = record.GetValue(“Date”).ToString(); 
    } 
    return cellValue;    

} 

  

  

Screenshot 

  

  

  

Sample Link 

http://www.syncfusion.com/downloads/support/forum/129237/ze/Hidden_column_value_on_cell_click-565795347  

  

Regards, 

Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon