How to change CellType in a row based another column''s value in runtime?
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++;
}
}
}
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++;
}
}
}
SIGN IN To post a reply.
3 Replies
KX
Ken Xu
June 8, 2007 05:44 AM UTC
But I found Nothing happened if I Set the CellType like the code snippet display, Please help me.
MA
Madhankumar
Syncfusion Team
June 8, 2007 05:47 PM UTC
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
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
KX
Ken Xu
June 11, 2007 08:52 AM UTC
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?
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?
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
KX Ken Xu
- Jun 8, 2007 05:36 AM UTC
- Jun 11, 2007 08:52 AM UTC