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.

How to change CellType in a row based another column''s value in runtime?

Thread ID:

Created:

Updated:

Platform:

Replies:

62120 Jun 8,2007 01:36 AM Jun 11,2007 04:52 AM Windows Forms 3
loading
Tags: GridControl
Ken Xu
Asked On June 8, 2007 01:36 AM

Hello,
Suppose next situation,

There's a GGC bind a parent table with child.
In the parent rows ,there're two fields - State & City.
Now ,if I change a row's State from California to North Carolina, then I demand the other field
must only show respective cities to select.

The Following if my code snippet:
void Grouping_RecordValueChanged(object sender, GridRecordValueChangedEventArgs e)
{
if (e.FieldDescriptor.Name == "State")
{
DataTable dtCity = service.GetCityByStateId(e.Record.GetValue("State"));

GridGroupingControl grdGrouping = (GridGroupingControl)sender;
int i = 3;
foreach (GroupBase.Record r in grdGrouping.Table.Records)
{
if (r.GetValue("ID") == e.Record.GetValue("ID"))
{
grdGrouping.TableModel.ColStyles["City"].CellModel.Grid[i, 7].CellType = "ComboBox";
grdGrouping.TableModel.ColStyles["city"].CellModel.Grid[i, 7].DisplayMember = "Name";
grdGrouping.TableModel.ColStyles["City"].CellModel.Grid[i, 7].ValueMember = "ID";
grdGrouping.TableModel.ColStyles["City"].CellModel.Grid[i, 7].DataSource = dtCity;
break;
}
i++;
}
}
}

Ken Xu
Replied On June 8, 2007 01:44 AM

But I found Nothing happened if I Set the CellType like the code snippet display, Please help me.

Madhankumar [Syncfusion]
Replied On June 8, 2007 01:47 PM

Hi Ken,

Thank you for being patience.

To set any cell specific properties, the QueryCellStyleInfo event have to be handled. The following is the logic need to be used to set the style properties. Please try it and let us know if you need any further assistance.

+++++++++ Code Snippet +++++++++++
Hashtable hash = new Hashtable();
void gridGroupingControl1_RecordValueChanged(object sender, RecordValueChangedEventArgs e)
{
if (e.FieldDescriptor.Name == "State")
{
hash.Clear();
DataTable dtCity = service.GetCityByStateId(e.Record.GetValue("State"));
object key = e.Record.GetValue("ID");
hash.Add(dtCity, key);
}
}

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record)
{
Record r = e.TableCellIdentity.DisplayElement.GetRecord();
object key = r.GetValue("ID");
if (hash.Contains(key))
{
if (e.TableCellIdentity.Column.Name == "Column3")
{
e.Style.CellType = "ComboBox";
e.Style.DisplayMember = "Name";
e.Style.DataSource = dtCity;
e.Style.ValueMember = "ID";
}
}
}
}
+++++++++ Code Snippet +++++++++++

Have a nice day.

Best regards,
Madhan

Ken Xu
Replied On June 11, 2007 04:52 AM

Thank you so deeply, Madhan.

You save me from a big trouble!
I have got it!~
The moving-link columns looks like quite good.

But now ,I'm having a headache on how to create a CheckedListBox Column here:
http://www.syncfusion.com/support/Forums/message.aspx?&MessageID=61999

Could you help me again?

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.

;