How can i show the values of an item while double clicking on any of the value.
I mean is when we point our mouse pointer to an of the item in grid,then there will be a tooltip showing the current details of that item.How can i show it in message box while double clicking on it?
Can anyone help me Please...
17 Answers, 1 is accepted
Thank you for writing.
You can achieve the desired behavior by subscribing your RadPivotGrid instance to the MouseDoubleClick event and in the handler display a message box with the relevant information for the cell which is being clicked:
private
void
radPivotGrid1_MouseDoubleClick(
object
sender, MouseEventArgs e)
{
string
res =
string
.Empty;
RadPivotGrid grid = (RadPivotGrid)sender;
LightVisualElement cell = grid.ElementTree.GetElementAtPoint(e.Location)
as
LightVisualElement;
if
(cell !=
null
)
{
if
(cell
is
PivotCellElement)
{
PivotCellElement pivotCell = (PivotCellElement)cell;
string
caption =
"Caption: "
+ pivotCell.AggregateDescription.DisplayName +
"\n"
;
string
value =
"Value: "
+ pivotCell.Text +
"\n"
;
string
row =
this
.GetScreenTipValue(pivotCell.Row,
"Row: "
) +
"\n"
;
string
col =
this
.GetScreenTipValue(pivotCell.Column,
"Column: "
) +
"\n"
;
res = caption + value + row + col;
}
else
if
(cell.ToolTipText !=
""
)
{
res = cell.ToolTipText;
}
else
if
(cell
is
PivotGroupElement)
{
res = cell.Text;
}
}
if
(res !=
string
.Empty)
{
MessageBox.Show(res);
}
}
private
string
GetScreenTipValue(PivotGroupNode value,
string
prefix)
{
IGroup group = value.Group;
if
(group !=
null
)
{
List<IGroup> parents =
new
List<IGroup>();
while
(group !=
null
)
{
parents.Add(group);
group = group.Parent;
}
StringBuilder sb =
new
StringBuilder();
sb.AppendFormat(
"{0}: "
, prefix);
int
count = parents.Count;
while
(count > 0)
{
count--;
if
(count > 0)
{
sb.AppendFormat(
"{0} - "
, parents[count].Name);
}
else
{
sb.AppendFormat(
"{0}"
, parents[count].Name);
}
}
return
sb.ToString();
}
return
String.Empty;
}
I am also sending you a gif file showing the result on my end.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Hi Sir
It really works.
Thankyou verymuch...
Can you do me a favour.. can you explain what you have done in the code.I'am not familar with some of codes like line5 and I'am new for telerik
What this code does is the following. When the double click event occurs, according to the mouse location, we get the pivot cell element clicked. Then we build the string with the needed information and we use a message box to display it.
I hope that you find this information useful.
Regards,
Stefan
Telerik
Hi Hristo,
Thank you for this post. This helped me lot.
One more thing i need is when i click on PivotGroupElement, can i get name of its RowGroupDescriptions ?
See in attached photo Please. If i click on "INV", in message box i want name "UserConstr".
Hope you will reply soon.
Thank you.
Thank you for writing.
Please see below how I modified the handler of the MouseDoubleClick event. Basically, you would need to get the level of the group node and depending whether it is on a row or a column map it to the RowGroupDescriptions or ColumnGroupDescriptions collections.
private
void
radPivotGrid1_MouseDoubleClick(
object
sender, MouseEventArgs e)
{
string
res =
string
.Empty;
RadPivotGrid grid = (RadPivotGrid)sender;
LightVisualElement cell = grid.ElementTree.GetElementAtPoint(e.Location)
as
LightVisualElement;
if
(cell !=
null
)
{
if
(cell
is
PivotCellElement)
{
PivotCellElement pivotCell = (PivotCellElement)cell;
string
caption =
"Caption: "
+ pivotCell.AggregateDescription.DisplayName +
"\n"
;
string
value =
"Value: "
+ pivotCell.Text +
"\n"
;
string
row =
this
.GetScreenTipValue(pivotCell.Row,
"Row: "
) +
"\n"
;
string
col =
this
.GetScreenTipValue(pivotCell.Column,
"Column: "
) +
"\n"
;
res = caption + value + row + col;
}
else
if
(cell.ToolTipText !=
""
)
{
res = cell.ToolTipText;
}
else
if
(cell
is
PivotGroupElement)
{
PivotGroupNode groupNode = ((PivotGroupElement)cell).Data;
int
level = groupNode.Group.Level;
string
agg =
string
.Empty;
if
(level <=
this
.radPivotGrid1.RowGroupDescriptions.Count)
{
PropertyGroupDescription desc =
null
;
if
(groupNode.Axis == PivotAxis.Rows)
{
desc =
this
.radPivotGrid1.RowGroupDescriptions[level]
as
PropertyGroupDescription;
}
else
{
desc =
this
.radPivotGrid1.ColumnGroupDescriptions[level]
as
PropertyGroupDescription;
}
if
(desc !=
null
)
{
agg = desc.PropertyName;
}
}
res = agg +
"\n"
+ cell.Text;
}
}
if
(res !=
string
.Empty)
{
MessageBox.Show(res);
}
}
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Hi Hristo,
Thank you sooooooo much. This is exactly what i wanted.
One more thing. Can we expand context menu ?
After 'Show Field List' in menu i want to add more options.Thank you for writing.
Yes, you can modify the context menu. For the purpose, you would need to inherit the PivotGridContextMenu class and depending on the context add your custom menu items:
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
MyPivotGridContextMenu menu =
new
MyPivotGridContextMenu(
this
.radPivotGrid1.PivotGridElement);
this
.radPivotGrid1.PivotGridElement.ContextMenu = menu;
}
}
public
class
MyPivotGridContextMenu : PivotGridContextMenu
{
public
MyPivotGridContextMenu(RadPivotGridElement pivotGridElement)
:
base
(pivotGridElement) { }
protected
override
void
AdjustItemsForContext()
{
base
.AdjustItemsForContext();
if
(
this
.Context
is
PivotCellElement)
{
RadMenuItem customMenuItem =
new
RadMenuItem();
customMenuItem.Text =
"Export to Excel"
;
RadMenuSeparatorItem separator =
new
RadMenuSeparatorItem();
this
.Items.Add(separator);
customMenuItem.Click += customMenuItem_Click;
this
.Items.Add(customMenuItem);
}
}
private
void
customMenuItem_Click(
object
sender, EventArgs e)
{
RadMessageBox.Show(
"Exported!"
);
}
}
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Thank you Hristo. You are a life saver.
Hi Hristo,
Is there any limitation to the number of rows we can see in pivot Grid ?
I am adding 14,50,000 into pivot grid but can't see any result.
Thank you for writing.
There is no limitation of the rows count in RadPivotGrid. In case you keep experiencing this issue please open up a support ticket and send us your project so that we can investigate it locally.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Hi,
I want to save the layout of PivotGrid whenever position of GroupDescription or AggregationDescription is changed.
Is there any event or method to do so ? I don't want to save layout on Button click.
Thank you for writing.
You can subscribe to the PivotGridElement.GroupDescriptorElementCreating and PivotGridElement.AggregateDescriptorElementCreating events which are fired when you add row/column descriptors or aggregate descriptors. However, note that when you reorder the available row descriptors, for example, the event will be fired again for all available descriptors because the pivot grid data is reloaded.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress
Hello Dess,
Thank you for your prompt Reply.
I have checked these events. Problem with these events is my function will be called for each row/column/aggregate descriptors.
What i want is if i drag any descriptor and drop it in Row/Column/Filter area a function should be called only once.
Thank you for writing back.
You can handle the PivotGridElement.DragDropService. event which is fired just once. Thus, when you drag a certain row descriptor and drop it in the columns descriptors area, the pivot data will be regenerated, the mentioned event will be fired and you can execute the desired action.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik by Progress
Thank you Dess. I think this will solve my problem. I will let you know if it doesn't help.
Regards,
Deepak
Hello,
I want to check no of children in each Descriptor. Like in attached png file, i want Commodity Row descriptor should return 1 value.
Idea is on a button click i want Column/Row Group Descriptor who has only one children should be moved to Filter area.
Thank you for writing.
You can get the unique group description for each of the rows by refreshing the values provider this way:
List<
object
> distinctItems;
private
void
radButton_Click(
object
sender, EventArgs e)
{
foreach
(PropertyGroupDescriptionBase groupDescription
in
this
.localDataProvider.RowGroupDescriptions)
{
DistinctValuesProvider valuesProvider = ((IDistinctValuesDescription)groupDescription).GetDisctinctValuesProvider();
valuesProvider.Updated +=
new
EventHandler<EventArgs>(ValuesProvider_Updated);
valuesProvider.Refresh();
}
}
private
void
ValuesProvider_Updated(
object
sender, EventArgs e)
{
DistinctValuesProvider valuesProvider = sender
as
DistinctValuesProvider;
valuesProvider.Updated -=
this
.ValuesProvider_Updated;
this
.distinctItems =
new
List<
object
>(valuesProvider.DisctinctValues);
}
Similarly, if you iterate the ColumnsGroupDescriptions collection you will get the unique column descriptions.
I would like to also note that we try to keep our forum threads focused on a single topic. In case you need further assistance and your question is not related to the original one or an existing one elsewhere, please create a new thread or open up a support ticket.
I hope this information is useful.
Regards,
Hristo Merdjanov
Telerik by Progress