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.
Unfortunately, activation email could not send to your email. Please try again.

Given a Record how can i refer a CELL

Thread ID:

Created:

Updated:

Platform:

Replies:

71064 Jan 14,2008 07:19 AM Jan 15,2008 02:11 AM Windows Forms 3
loading
Tags: GridControl
John Ruiz
Asked On January 14, 2008 07:19 AM

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.


Jeba S [Syncfusion]
Replied On January 15, 2008 12:20 AM

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.






John Ruiz
Replied On January 15, 2008 01:44 AM



>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


Jeba S [Syncfusion]
Replied On January 15, 2008 02:11 AM

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.



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;