Replies
Hi,
As mike said you can also try with ColumnHeader. But the coding pattern remains same.
Hi,
As I understood that you want to know whether the user clicked on the column header or not? If this is correct, You can use the below code to detect whether the user clicks on the column header or not. If I misunderstood your scenario please elaborate your question so that I can help.
Dim ugColl As UltraGridColumn = uiElement.GetContext(GetType(UltraGridColumn))
If (ugCell Is Nothing And ugColl IsNot Nothing) Then
' your code goes here
End If
[quote user="dpbouchard"]
I would like to know if I right-clicked on the cell header. How do I do this?
My current code:
Private Sub ugCommission_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ugCommission.MouseUp Dim cmItemNum As New ContextMenuStrip Dim cmCommDue As New ContextMenuStrip If e.Button = Windows.Forms.MouseButtons.Right Then Dim ptCurrent As Point = New Point(e.X, e.Y) Dim uiElement As Infragistics.Win.UIElement = CType(sender, UltraGrid).DisplayLayout.UIElement.ElementFromPoint(ptCurrent) Dim ugCell As UltraGridCell = uiElement.GetContext(GetType(UltraGridCell)) Dim ugRow As UltraGridRow = uiElement.GetContext(GetType(UltraGridRow)) ' Thought ugUIElement would be it, but it is also nothing when I right click on the col header cell
Dim ugUIElement As UltraGridUIElement = uiElement.GetContext(GetType(UltraGridUIElement)) If ugCell IsNot Nothing Then ugCommission.Selected.Rows.Clear() ugRow.Selected = True If ugCell.Column.Key = "ITEM_NUM" Then _cmItemNum.Show(ugCommission, ptCurrent) ElseIf ugCell.Column.Key = "COMM_DUE" Then _cmCommDue.Show(ugCommission, ptCurrent) End If End If End If End Sub
[/quote]
Hi Mike,
As you said we can't apply a context menu to a part of a control if we choose the "ContextMenuStrip" property for ultragrid control. I tried MouseDown event to assign or remove the context menu. Although the below code works fine if and only if you remove the "ContextMenuStrip" property for ultragrid control. Because it overrides the below code and displays the context menu whereever you click the mouse within the control.
********************************************************************************
private void ugQueue_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point mousePoint = new Point(e.X, e.Y);
UIElement element = ((UltraGrid)sender).DisplayLayout.UIElement.ElementFromPoint(mousePoint);
UltraGridCell cell = element.GetContext(typeof(UltraGridCell)) as UltraGridCell;
if (cell != null)
{
if (Convert.ToByte(cell.Row.Cells["Status"].Value) == 0)
{
cmnuQueue.Show(ugQueue, mousePoint);
cell.Row.Selected = true;
}
else
return;
}
}
}
********************************************************************************
Thanks Mike.
With Regards,
SreeRam.
Once again Thanks Mr. Mike.
I made changes to my code so that adding unbounded columns in the InitializeLayout event. I specified the datatype and the visible position also.
By the way I have another problem which I mentioned in my previous reply. Please consider my sample code and suggest the solution to that DateTime problem.
Thanks a lot.
With regards,
SreeRam.
Thanks Mr. Mike.
However I worked it out in the following way. Please suggest me whether it is correct or not? If there is any best way please mention with the sample code [I think you will understand my requirement by seeing the below code. Most important thing to remember is that I'm getting the data source from the business logic layer instead of direct access to datasets].
I found another problem with the column "EntryTime". There I need to display the time or both date and time of entry instead of onlf date.But the grid displays only date. How can I format the column so that it displays Date and Time or only Time?
*********************************************************************************************************************
private void FillTodaysQueue()
{
QueueMaster queueMaster = new QueueMaster();
if (!ugQueue.DisplayLayout.Bands[0].Columns.Contains("ElapsedTime"))
{
ugQueue.DisplayLayout.Bands[0].Columns.Add("ElapsedTime", "Elapsed Time");
}
ugQueue.DataSource = queueMaster.GetTodayQueue();
ugQueue.Refresh();
ugQueue.DisplayLayout.Bands[0].Columns["Sno"].Width = 30;
// Hide unneccessary columns
ugQueue.DisplayLayout.Bands[0].Columns["QueueId"].Hidden = true;
ugQueue.DisplayLayout.Bands[0].Columns["PatientId"].Hidden = true;
ugQueue.DisplayLayout.Bands[0].Columns["ConsultantId"].Hidden = true;
ugQueue.DisplayLayout.Bands[0].Columns["ExitTime"].Hidden = true;
ugQueue.DisplayLayout.Bands[0].Columns["EntryTime"].Header.Caption = "Entry Time";
// Hide filter icon on unneccessary columns
//ugQueue.DisplayLayout.Bands[0].Columns["ElapsedTime"].AllowRowFiltering = DefaultableBoolean.False;
ugQueue.DisplayLayout.Bands[0].Columns["Sno"].AllowRowFiltering = DefaultableBoolean.False;
ugQueue.DisplayLayout.Bands[0].Columns["PatientId"].AllowRowFiltering = DefaultableBoolean.False;
ugQueue.DisplayLayout.Bands[0].Columns["EntryTime"].AllowRowFiltering = DefaultableBoolean.False;
//ugQueue.DisplayLayout.Bands[0].Columns["ConsultantId"].Width = 150;
//ugQueue.DisplayLayout.Bands[0].Columns["EntryTime"].Width = 125;
//ugQueue.DisplayLayout.Bands[0].Columns["ElapsedTime"].Width = 100;
//ugQueue.DisplayLayout.Bands[0].Columns["ElapsedTime"].Swap(ugQueue.DisplayLayout.Bands[0].Columns["Status"]);
FillValueLists();
queueMaster.Dispose();
}
/// <summary>
/// Displays Consultant Name instead of ConsultantId,
/// Patient name instead of Patient Id, etc…
/// </summary>
private void FillValueLists()
{
ugQueue.DisplayLayout.ValueLists.Add("PatientType");
ugQueue.DisplayLayout.ValueLists["PatientType"].ValueListItems.Add(0, "New");
ugQueue.DisplayLayout.ValueLists["PatientType"].ValueListItems.Add(1, "Old");
ugQueue.DisplayLayout.ValueLists["PatientType"].ValueListItems.Add(2, "Renew");
ugQueue.DisplayLayout.ValueLists["PatientType"].DisplayStyle = ValueListDisplayStyle.DisplayText;
ugQueue.DisplayLayout.Bands[0].Columns["PType"].ValueList = ugQueue.DisplayLayout.ValueLists["PatientType"];
ugQueue.DisplayLayout.ValueLists.Add("QueueType");
ugQueue.DisplayLayout.ValueLists["QueueType"].ValueListItems.Add(0, "Appointment");
ugQueue.DisplayLayout.ValueLists["QueueType"].ValueListItems.Add(1, "General");
ugQueue.DisplayLayout.ValueLists["QueueType"].ValueListItems.Add(2, "");
ugQueue.DisplayLayout.ValueLists["QueueType"].DisplayStyle = ValueListDisplayStyle.DisplayText;
ugQueue.DisplayLayout.Bands[0].Columns["QType"].ValueList = ugQueue.DisplayLayout.ValueLists["QueueType"];
ugQueue.DisplayLayout.ValueLists.Add("Status");
ugQueue.DisplayLayout.ValueLists["Status"].ValueListItems.Add(0, "Pending");
ugQueue.DisplayLayout.ValueLists["Status"].ValueListItems.Add(1, "");
ugQueue.DisplayLayout.ValueLists["Status"].DisplayStyle = ValueListDisplayStyle.DisplayText;
ugQueue.DisplayLayout.Bands[0].Columns["Status"].ValueList = ugQueue.DisplayLayout.ValueLists["Status"];
}