Retrieve Selected row and located cells in the row

Hi,
 
I am very new to the GridControl.
 
After the GridControl is populated with a collection of data through the adaptor and displayed on the screen, when any row is selected in the GridControl, how could I get hold of the selected Row?
 
I would also need to change the background color of the cell. e.g. The second cell of the selected row when the row is selected.
 
I am using C# and Windform.
 
Thanks

3 Replies

AK Arun Kumar V Syncfusion Team July 18, 2013 04:01 AM UTC

Hi YU,

Thanks for your interest in Syncfusion products.

Query:

GridControl backcolor change.

 

The selected row can be achieved in many ways. Please refer to the following UG which is similar to your inquiry.

http://help.syncfusion.com/ug/windows%20forms/grid/default.htm#!documents/5137howcanwemakethecurrentrowbold.htm

You can use the CurrentCellChanged and CurrentCellValidateString events to capture the current cell text also when the text changed is changed.

Code snippet:

1.)

this.gridControl1.CurrentCellChanged += new EventHandler(gridControl1_CurrentCellChanged);

private void gridControl1_CurrentCellChanged(object sender, System.EventArgs e)

{

GridCurrentCell cc = this.gridControl1.CurrentCell; Console.WriteLine("CurrentCellChanged :" + cc.Renderer.ControlText);   

}

this.gridControl1.CurrentCellValidateString += new GridCurrentCellValidateStringEventHandler(gridControl1_CurrentCellValidateString);

private void gridControl1_CurrentCellValidateString(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellValidateStringEventArgs e)

{

GridCurrentCell cc = this.gridControl1.CurrentCell; Console.WriteLine("CurrentCellValidateString :" + cc.Renderer.ControlText);  

}

2.)

You can get the updated value by using AcceptedChanges event. Please refer to the following code.

this.gridControl1.CurrentCellAcceptedChanges += new CancelEventHandler(gridControl1_CurrentCellAcceptedChanges);

this.gridControl1.CurrentCellDeactivated += newGridCurrentCellDeactivatedEventHandler(gridControl1_CurrentCellDeactivated);

this. gridControl1.CurrentCellValidating += newCancelEventHandler(gridControl1_CurrentCellValidating);

void gridControl1_CurrentCellAcceptedChanges(object sender,CancelEventArgs e)

{

}

void gridControl1_CurrentCellValidating(object sender,CancelEventArgs e)

{

}

void gridControl1_CurrentCellDeactivated(object sender,GridCurrentCellDeactivatedEventArgs e)

{

}

3.)

//Occurs before the current cell switches into editing mode

this.gridControl1.CurrentCellStartEditing += newCancelEventHandler(gridControl1_CurrentCellStartEditing);

//Occurs when the grid completes editing mode, i.e., when the active current cell exits the editing mode

this.gridControl1.CurrentCellEditingComplete += newEventHandler(gridControl1_CurrentCellEditingComplete);

//Occurs when the grid accepts changes made to the active current cell

this.gridControl1.CurrentCellAcceptedChanges += newCancelEventHandler(gridControl1_CurrentCellAcceptedChanges);

 

Please let me know if you have any concerns.

Regards,

Arun.



PL Phien Le replied to Arun Kumar V March 26, 2018 08:42 AM UTC

Hi YU,

Thanks for your interest in Syncfusion products.

Query:

GridControl backcolor change.

 

The selected row can be achieved in many ways. Please refer to the following UG which is similar to your inquiry.

http://help.syncfusion.com/ug/windows%20forms/grid/default.htm#!documents/5137howcanwemakethecurrentrowbold.htm

You can use the CurrentCellChanged and CurrentCellValidateString events to capture the current cell text also when the text changed is changed.

Code snippet:

1.)

this.gridControl1.CurrentCellChanged += new EventHandler(gridControl1_CurrentCellChanged);

private void gridControl1_CurrentCellChanged(object sender, System.EventArgs e)

{

GridCurrentCell cc = this.gridControl1.CurrentCell; Console.WriteLine("CurrentCellChanged :" + cc.Renderer.ControlText);   

}

this.gridControl1.CurrentCellValidateString += new GridCurrentCellValidateStringEventHandler(gridControl1_CurrentCellValidateString);

private void gridControl1_CurrentCellValidateString(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellValidateStringEventArgs e)

{

GridCurrentCell cc = this.gridControl1.CurrentCell; Console.WriteLine("CurrentCellValidateString :" + cc.Renderer.ControlText);  

}

2.)

You can get the updated value by using AcceptedChanges event. Please refer to the following code.

this.gridControl1.CurrentCellAcceptedChanges += new CancelEventHandler(gridControl1_CurrentCellAcceptedChanges);

this.gridControl1.CurrentCellDeactivated += newGridCurrentCellDeactivatedEventHandler(gridControl1_CurrentCellDeactivated);

this. gridControl1.CurrentCellValidating += newCancelEventHandler(gridControl1_CurrentCellValidating);

void gridControl1_CurrentCellAcceptedChanges(object sender,CancelEventArgs e)

{

}

void gridControl1_CurrentCellValidating(object sender,CancelEventArgs e)

{

}

void gridControl1_CurrentCellDeactivated(object sender,GridCurrentCellDeactivatedEventArgs e)

{

}

3.)

//Occurs before the current cell switches into editing mode

this.gridControl1.CurrentCellStartEditing += newCancelEventHandler(gridControl1_CurrentCellStartEditing);

//Occurs when the grid completes editing mode, i.e., when the active current cell exits the editing mode

this.gridControl1.CurrentCellEditingComplete += newEventHandler(gridControl1_CurrentCellEditingComplete);

//Occurs when the grid accepts changes made to the active current cell

this.gridControl1.CurrentCellAcceptedChanges += newCancelEventHandler(gridControl1_CurrentCellAcceptedChanges);

 

Please let me know if you have any concerns.

Regards,

Arun.


you agree to the privacy policy and terms of service.


SN Sindhu Nagarajan Syncfusion Team March 27, 2018 07:16 AM UTC

Hi Phien, 

Thanks for the update. 

Please explain your queries with some more details, so that we will be able to assist you. 

Regards, 
Sindhu  


Loader.
Up arrow icon