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

Make the Grid inactive except the current row.

Haneef,

I have a grid where I can add a new row on a button click.

1. I need to set the new row added as the Active/Current/Selected/pointed Row
2. I need the rest of the rows to be disabled. and the textcolor = SystemColors.InactiveCaptionText

It would be great if you could provide a small code snippet to do the same.

Thanks a lot.
Grace

3 Replies

RA Rajagopal Syncfusion Team July 26, 2007 03:30 PM UTC

Hi Grace,

Thanks for your interest in Syncfusion Products.

1. To set the new row added as the active current row, try the code below in your button click handler.

int lastAddedRecord = this.gridGroupingControl1.Table.Records.Count-1;
this.gridGroupingControl1.Table.Records[lastAddedRecord].SetCurrent();

2. To disable all the rows except the current row, please try the code below in the QueryCellStyleInfo event of the GridGroupingControl.

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
Element el = e.TableCellIdentity.DisplayElement;
if (el.Kind == DisplayElementKind.Record)
{
Record rec = el.GetRecord();
if (e.TableCellIdentity.ColIndex > 0 && e.TableCellIdentity.Table.CurrentRecord != rec)
{
e.Style.TextColor = SystemColors.InactiveCaptionText;
e.Style.CellType = "Static";
}
}
}

Please try the above code and let me know if this helps.

Have a nice time.
Regards,
Rajagopal


NG ngp July 26, 2007 05:07 PM UTC

Hi Rajagopal,

My underlying datasource is ArrayList and Not Datatable

What woudl be the change?

Thanks
Grace



>Hi Grace,

Thanks for your interest in Syncfusion Products.

1. To set the new row added as the active current row, try the code below in your button click handler.

int lastAddedRecord = this.gridGroupingControl1.Table.Records.Count-1;
this.gridGroupingControl1.Table.Records[lastAddedRecord].SetCurrent();

2. To disable all the rows except the current row, please try the code below in the QueryCellStyleInfo event of the GridGroupingControl.

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
Element el = e.TableCellIdentity.DisplayElement;
if (el.Kind == DisplayElementKind.Record)
{
Record rec = el.GetRecord();
if (e.TableCellIdentity.ColIndex > 0 && e.TableCellIdentity.Table.CurrentRecord != rec)
{
e.Style.TextColor = SystemColors.InactiveCaptionText;
e.Style.CellType = "Static";
}
}
}

Please try the above code and let me know if this helps.

Have a nice time.
Regards,
Rajagopal


RA Rajagopal Syncfusion Team July 27, 2007 12:34 AM UTC

Hi Grace,

If you are using Arraylist as the datasource for the grid, then grid does not respond to changes in the data source, the data source has to implement the IBindingList interface. DataTable does this, but ArrayList does not. But you can derive an ArrayList so it does implement IBindingList. If you do this, then the grid should display the changes as they are made to the arraylist.

Please refer the sample below that meets your requirements
http://websamples.syncfusion.com/samples/Grid.Windows/F65519/main.htm

Let me know if you have any other questions.
Regards,
Rajagopal

Loader.
Live Chat Icon For mobile
Up arrow icon