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

Given a Record how can i refer a CELL

Given a record how can i refer to a cell (say column XYZ) in the record?
I would like to show the exclamation error icon for a particular cell when one of the other cell contains some particular value. I only have reference to record.


3 Replies

JS Jeba S Syncfusion Team January 15, 2008 05:20 AM UTC

Hi John,

Thank you for posting query to us.

You can use the Record.GetValue() method to retrieve the cell value of a particular column. In the QueryCellStyleInfo event, the record's value is retrieved as an object. Then compare the record value with the conditional value and assign the icon accordingly. The code for the QueryCellStyleInfo event is as follows.


private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.Column != null
&& e.TableCellIdentity.Column.Name == "Col2")
{
GridRecord rec = e.TableCellIdentity.DisplayElement.GetRecord() as GridRecord;
if (rec != null)
{
object val = rec.GetValue("Col1");
if (val.ToString() == "row0 col1")
{
e.Style.ImageList =this.imageList;
e.Style.ImageIndex = 0;
}
}
}
}


Please refer the below sample and let us know if this helps.
http://websamples.syncfusion.com/samples/Grid.Windows/F71064/main.htm

Regards,
Jeba.







JR John Ruiz January 15, 2008 06:44 AM UTC



>Hi John,

Thank you for posting query to us.

You can use the Record.GetValue() method to retrieve the cell value of a particular column. In the QueryCellStyleInfo event, the record's value is retrieved as an object. Then compare the record value with the conditional value and assign the icon accordingly. The code for the QueryCellStyleInfo event is as follows.


private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.Column != null
&& e.TableCellIdentity.Column.Name == "Col2")
{
GridRecord rec = e.TableCellIdentity.DisplayElement.GetRecord() as GridRecord;
if (rec != null)
{
object val = rec.GetValue("Col1");
if (val.ToString() == "row0 col1")
{
e.Style.ImageList =this.imageList;
e.Style.ImageIndex = 0;
}
}
}
}


Please refer the below sample and let us know if this helps.
http://websamples.syncfusion.com/samples/Grid.Windows/F71064/main.htm

Regards,
Jeba.








Thanks for the code sample.

My program has reference to all the rows of 40 columns using a hashtable where the key is the stock code and the value is the row in the datagrid as mentioned.

Now given a stock quote i need to quickly obtain the cell reference based on the column name (for the given row) so i could set the exception when there is a wrong value. Could you please tell me how to go about it?

Thanks
John



JS Jeba S Syncfusion Team January 15, 2008 07:11 AM UTC

Hi John,

Thank you for your update.

You can handle the CurrentCellValidating event to validate the current cell. Below is the code snippet for validation:


private void gridGroupingControl1_TableControlCurrentCellValidating( object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCancelEventArgs e )
{
object cellVal = e.TableControl.CurrentCell.Renderer.ControlValue;
string cellText = e.TableControl.CurrentCell.Renderer.ControlText;

if ( ( cellVal == null )
&& ( ( cellText != String.Empty )
|| ( cellText != null ) ) )
{
MessageBox.Show( "error" );
e.Inner.Cancel = true;
int row = e.TableControl.CurrentCell.RowIndex;
int col = e.TableControl.CurrentCell.ColIndex;
e.TableControl.CurrentCell.MoveTo(row, col, GridSetCurrentCellOptions.SetFocus);
}
}
}



Please refer to the below KB article for more details on Validation.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=340

Kindly let us know if you need any further assistance.

Regards,
Jeba.



Loader.
Live Chat Icon For mobile
Up arrow icon