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.
Syncfusion Feedback

No search in NestedTableCell''s with GridFindReplaceDialogSink.Find

Thread ID:

Created:

Updated:

Platform:

Replies:

100632 Aug 19,2011 05:38 PM UTC Oct 11,2011 03:44 AM UTC ASP.NET Web Forms (Classic) 5
loading
Tags: Grouping
Andrey Fedotov
Asked On August 19, 2011 05:38 PM UTC

Hi!
I'm using Essential Studio 7.0.1.20 and WinForms.
I came across a GGC search problem. GridFindReplaceDialogSink.Find does not work inside nested table cells. Is there any workaround? Thank you in advance!


Christopher Issac Sunder K [Syncfusion]
Replied On August 30, 2011 06:01 AM UTC

Hi,

Thank you for your interest in Syncfusion products.

Regret for the delay. You can make use of the below code to achieve the find and replace option for child tables. Here GetTableControl() method is used to get the child’s TableControl. We need to mention the name of the ChildTable as parameter in GetTableControl().

GridFindReplaceEventArgs frEvents = new GridFindReplaceEventArgs(txtSearch.Text, "", searchOptions, locInfo);
//GridFindReplaceDialogSink frDialog = new GridFindReplaceDialogSink(gridGroupingControl1.TableControl);
GridFindReplaceDialogSink frDialog = new GridFindReplaceDialogSink(gridGroupingControl1.GetTableControl("ChildTable"));
frDialog.Find(frEvents);


Let us know if you have any concerns.

Regards,
Christo.



Andrey Fedotov
Replied On September 24, 2011 03:08 PM UTC

Below is my ugly solution. I hope it is self-evident for what SearchForWhatTextBox, CaseSensitiveCheckBox, EntireTableRadioButton, etc are used.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel;
using System.Text;
using Syncfusion.Grouping;
using Syncfusion.Windows.Forms.Grid;
using Syncfusion.Windows.Forms.Grid.Grouping;

namespace SyncfusionForms
{

public class GridGroupingControlNestedSearchForm : Office2007Form
{

private static object GetDataSourceDisplayValue(IBindingList bindinglist,
string displaymember, string valuemember, object value)
{
foreach (object item in bindinglist)
{
PropertyInfo valueproperty = item.GetType().GetProperty(valuemember);
PropertyInfo displayproperty = item.GetType().GetProperty(displaymember);

if (valueproperty.GetValue(item, null).Equals(value))
return displayproperty.GetValue(item, null);
}
return null;
}


// i.e. grigGroupingControl1.TableControl
private GridTableControl _tableControl;

private GridFindTextOptions _options;

// true only on searching inside current record
private bool _insideCurrentRecord = false;
// true only on searching after current record
private bool _afterCurrentRecord = false;


public GridGroupingControlNestedSearchForm(GridTableControl tc)
{
InitializeComponent();
_options = GridFindTextOptions.None;
_tableControl = tc;

}

// s contains a cell value; TextToSearch holds a string to look up for
protected bool CompareString(string s)
{
if (string.IsNullOrEmpty(s)) return false;
StringComparison comparisontype = StringComparison.CurrentCultureIgnoreCase;
if ((Options & GridFindTextOptions.MatchCase) == GridFindTextOptions.MatchCase)
comparisontype = StringComparison.CurrentCulture;
if ((Options & GridFindTextOptions.MatchWholeCell) == GridFindTextOptions.MatchWholeCell)
{
if (string.Compare(s, TextToSearch, comparisontype) == 0)
return true;

}
else if (s.IndexOf(TextToSearch, comparisontype) != -1)
return true;
return false;
}

private string TextToSearch
{
get
{
return SearchForWhatTextBox.Text;
}
}

private GridTableControl TableControl
{
get
{
return _tableControl;
}
}

private void SetOptions()
{
_options = GridFindTextOptions.None;
if (CaseSensitiveCheckBox.Checked)
_options = GridFindTextOptions.MatchCase;
if (EntireCellCheckBox.Checked)
_options |= GridFindTextOptions.MatchWholeCell;
if (ReverseSearchRadioButton.Checked)
_options |= GridFindTextOptions.SearchUp;

if (EntireTableRadioButton.Checked) _options |= GridFindTextOptions.WholeTable;
else _options |= GridFindTextOptions.ColumnOnly;

}

// search is one-directional, column-unrelated, so irrelevant controls must be disabled
private void TableSearchForm_Load(object sender, EventArgs e)
{
EntireTableRadioButton.Checked = true;
CurrentColumnRadioButton.Enabled = false;
ForwardSearchRadioButton.Checked = true;
ReverseSearchRadioButton.Enabled = false;
}

private void FindNextButton_Click(object sender, EventArgs e)
{
try
{
SetOptions();
if (TextToSearch != "")
{

_insideCurrentRecord = false;
_afterCurrentRecord = false;
try
{

IterateThroughEntireElements(TableControl.Table.Elements,
TableControl.GroupingControl.TableModel);
}
catch (Exception)
{
}
}
}
catch (Exception)
{
}
}

// the main job being done here.
// IterateThroughEntireElements enumerates all the Record's inside the entire TableControl (with recursion).
private void IterateThroughEntireElements(IList arrelements, GridTableModel tablemodel)
{
// there are 3 states of the search:
// 1. before the current record - nothing to search (initial);
// 2. inside the current record - only fields after the current one must be processed;
// 3. after the current record - all the fields must be searched inside.
foreach (Element element in arrelements)
{

if (element.Kind == DisplayElementKind.Record)
{
Record rec = Element.GetRecord(element);
if (!_afterCurrentRecord)
{
// 1 -> 2
if (rec.IsCurrent) _insideCurrentRecord = true;
}

if (_insideCurrentRecord && !rec.IsCurrent)
{
// 2 -> 3
_insideCurrentRecord = false;
_afterCurrentRecord = true;
}
// if 2 or 3
if (_insideCurrentRecord || _afterCurrentRecord)
{
// the current field index (when 2)
int currentrelativeindex = -1;

if (_insideCurrentRecord)
{
// 2
FieldDescriptor cfd = tablemodel.Table.CurrentRecordManager.CurrentField;
currentrelativeindex =
((GridTableDescriptor)cfd.TableDescriptor).Columns[cfd.Name].GetRelativeColumnIndex();
}

for (int i = 0; i < tablemodel.Table.TableDescriptor.Columns.Count; ++i)
{
FieldDescriptor fd =
rec.ParentTableDescriptor.Fields[tablemodel.Table.TableDescriptor.Columns[i].Name];

GridStyleInfo styleinfo = tablemodel.ColStyles[i];
GridTableDescriptor tabledescriptor = (GridTableDescriptor)fd.TableDescriptor;
if (tabledescriptor.Columns.IndexOf(fd.Name) >= 0 && (currentrelativeindex == -1 ||
tabledescriptor.Columns[fd.Name].GetRelativeColumnIndex() > currentrelativeindex))
{
GridCellRendererBase renderer =
tablemodel.ActiveGridView.CellRenderers[tabledescriptor.Columns[fd.Name].Appearance.AnyRecordFieldCell.CellType];
String s;
// GridComboBoxCellModel seems unable to return a DisplayValue,
// we try to perform a manual lookup using Appearance.AnyRecordFieldCell.DataSource
// when possible
GridTableCellStyleInfo anyrecordcellstyle =
tabledescriptor.Columns[fd.Name].Appearance.AnyRecordFieldCell;
if (anyrecordcellstyle.DataSource != null &&
anyrecordcellstyle.DataSource is IBindingList &&
!String.IsNullOrEmpty(anyrecordcellstyle.DisplayMember))
{
object displayvalue = GetDataSourceDisplayValue((IBindingList)anyrecordcellstyle.DataSource,
anyrecordcellstyle.DisplayMember, anyrecordcellstyle.ValueMember,
rec.GetValue(fd));
if (displayvalue != null) s = displayvalue.ToString();
else s = rec.GetValue(fd).ToString();
}
else
{
// otherwise asks the CellModel to return the displayed text
s = renderer.Model.GetFormattedText(styleinfo,
rec.GetValue(fd), GridCellBaseTextInfo.DisplayText);
}
if (CompareString(s))
{
TableControl.Table.CurrentRecordManager.CurrentRecord = rec;
TableControl.ScrollInView(rec);
tablemodel.Table.CurrentRecordManager.NavigateTo(rec, true, true);
tablemodel.Table.CurrentRecordManager.CurrentRecord.SetCurrent(fd.Name);
// throws an exception to stop the recursion
throw new Exception("");
}
}
}


}
// checks whether the current record has nestedTables
if (rec.IsExpanded && rec.NestedTables.Count > 0)
{

foreach (GridNestedTable gnt in rec.NestedTables)
{

IterateThroughEntireElements(gnt.ChildTable.Elements,
TableControl.GroupingControl.GetTableModel(gnt.ChildTable.Name));

}
}
}

}
}



}

}




Asarudheen S [Syncfusion]
Replied On September 29, 2011 01:30 PM UTC

Hi,

Thanks for your interest in Syncfusion products.

Since we are not able to get your actual intension from your query, could you please share us more information probably a sample or your layout manager’s code which reproduces the reported issue, which will be more helpful for us to provide a better solution to you?

Please let us know if you have any queries.

Regards,
Asarudheen.


Andrey Fedotov
Replied On October 10, 2011 11:09 AM UTC

Sorry for answering so late. My solution, despite being overcomplicated, works fine for me. That's why I've posted a part of it. The question is resolved and the thread should be closed. Thank you for your suggestions, anyway.



Asarudheen S [Syncfusion]
Replied On October 11, 2011 03:44 AM UTC

Hi Andrey,

We are glad to hear that your issue has been resolved.

Please open a new support thread if you have any other concerns if you want us to follow up with this issue so that we will be happy to assist you.

Thanks for using Syncfusion Products.

Regards,
Asarudheen.


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.

Warning Icon 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.Close Icon

;