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

Use of Records.FindRecord not working

Hi,
I'm trying to find a row in a GGC based on a given value in a given column. On finding that row I then want to highlight it (i.e. as if it had been clicked so that the corresponding events then fire - so conditional formatting isn't what I want.)

I have used numerous snippets from various threads on this forum and seem to be able to successfully find the key field value i want but when I try and locate the record using
int index = GGC.treeList1.Table.TopLevelGroup.Records.FindRecord(keyFieldValue);
it ALWAYS returns 0. I'm a bit bemused that there isn't a method on the GGC such as FindRow([Column], [Value]) - maybe I have missed it??
I have attached one of your example apps, modified - the code executes when you click the "Find" button and the behaviour is the same on both your example grid and my attempted one.
Can you figure out what is going wrong/advise me a better way of doing what I want?
Thanks
Paul

SelfRelations.zip

8 Replies

J. J.Nagarajan Syncfusion Team September 8, 2007 04:28 AM UTC

Hi Paul,

You can implement searching in gridgroupingcontrol by employing the GridFindReplaceDialogSink class and the GridFindReplaceDialog class. Please try the code below in a button click event handler.

GridCurrentCell cc = this.gridGroupingControl1.TableControl.CurrentCell;
if (cc.RowIndex == -1 || cc.ColIndex == -1)
this.gridGroupingControl1.TableControl.CurrentCell.Activate(1, 1);
else
this.gridGroupingControl1.TableControl.CurrentCell.Activate(cc.RowIndex, cc.ColIndex);

GridFindReplaceDialog frmdialog = GridFindReplaceDialog.Instance;
GridFindReplaceDialogSink frds = null;
frds = new GridFindReplaceDialogSink(this.gridGroupingControl1.TableControl);
frmdialog.StartPosition = FormStartPosition.CenterScreen;
frmdialog.SetState(frds, "", false);
frmdialog.ShowDialog();


Regards,
Nagaraj


J. J.Nagarajan Syncfusion Team September 8, 2007 04:40 AM UTC

Hi Paul,

Also please take a look into this forum thread.

http://www.syncfusion.com/support/Forums/message.aspx?MessageID=42880

Regards,
Nagaraj


PS Paul Sullivan September 10, 2007 08:50 AM UTC

Thanks, Nagarajan. Unfortunately I need to find a value which I am passed from another part of the app, so a pop-up dialogue box is not going to fulfil my requirement here.


PS Paul Sullivan September 10, 2007 10:25 AM UTC

Nagarajan,
Also I am using the GridGroupingControl so am unable to use GridFindReplaceDialogSink as it requires GridControlBase


J. J.Nagarajan Syncfusion Team September 11, 2007 08:03 PM UTC

Hi Paul,

If you just want to highlight a record based on a particular column please use the following code snippet

private Record FindRow(string column, string searchString)
{
Record searchRow = null;
foreach (Record rec in gridGroupingControl1.Table.FilteredRecords)
{
if (rec.GetValue(column).ToString() == searchString)
{
searchRow = rec;
gridGroupingControl1.Table.SelectedRecords.Clear();

gridGroupingControl1.Table.SelectedRecords.Add(rec);
rec.SetCurrent(column);
break;
}
}
return searchRow;
}

Please refer to the attached sample. In this sample please do the following

1. Run the sample.
2. Select a cell in Column1.
3. Type "Row1" in that particular cell.
4. Click on the "search" button, you can highlight that parcular Row.

You can download the sample from the following page.

http://websamples.syncfusion.com/samples/Grid.Windows/F68091/main.htm

Please refer to the sample and let me know if you have any questions.

Regards,
Nagaraj


PS Paul Sullivan September 12, 2007 09:26 AM UTC

Hi Nagarajan,
Please run the demo app I atached to my post. The demo uses the Self-relation functionality of the GGC. When this functionality is being used the SetCurrent method you quoted does not work if the found row is a child row within the self-related grid. Please advise.
Thanks
Paul


JS Jeba S Syncfusion Team September 26, 2007 06:45 AM UTC

Hi Paul,

If you want to set a record in the child table as current record, then you should expand its parent record and then set the corresponding record as current.

Please refer this code snippets:

Record parent = null;
Record rec = null;
private void button5_Click(object sender, EventArgs e)
{
string column = "Curve name";
foreach (Record r in gridGroupingControl2.Table.Records)
{
foreach (Record rc in r.NestedTables[0].ChildTable.Records)
{
if (rc.GetValue(column).ToString() == "CRD DS ERICSSON EUR")
{
parent = r;
rec = rc;
break;
}
}
}
parent.IsExpanded = true;
rec.SetCurrent();

}


Please refer the samplw which implements the above said feature:
http://websamples.syncfusion.com/samples/Grid.Windows/F68087_Sample/main.htm

Kindly let us know if you need any further assistance.

Best Regards,
Jeba.


JS Jeba S Syncfusion Team September 26, 2007 06:47 AM UTC

Hi Paul,

If you want to set a record in the child table as current record, then you should expand its parent record and then set the corresponding record as current.

Please refer this code snippets:

Record parent = null;
Record rec = null;
private void button5_Click(object sender, EventArgs e)
{
string column = "Curve name";
foreach (Record r in gridGroupingControl2.Table.Records)
{
foreach (Record rc in r.NestedTables[0].ChildTable.Records)
{
if (rc.GetValue(column).ToString() == "CRD DS ERICSSON EUR")
{
parent = r;
rec = rc;
break;
}
}
}
parent.IsExpanded = true;
rec.SetCurrent();

}


Please refer the samplw which implements the above said feature:
http://websamples.syncfusion.com/samples/Grid.Windows/F68087_Sample/main.htm

Kindly let us know if you need any further assistance.

Best Regards,
Jeba.

Loader.
Live Chat Icon For mobile
Up arrow icon