Home - Forums-.NET - FlyGrid.Net (Windows Forms) - ContextMenu not working correctly...

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

ContextMenu not working correctly...
Link Posted: 06-Oct-2005 09:46
I have a flygrid which has 2 columns and 2 rows that are datetimepicker cells. I have associated a contextmenu with the flygrid, and when I right click over a date the contextmenu appears as expected.

The problem is when I click (left mouse button) on a cell the dropdown arrow appears for the datetimepicker, but if I then right click on that cell my contextmenu does not appear, the standard windows cut, paste, select all etc. contextmenu appears. How can I get around this???

Also another question, on my contextmenu I have got an option to 'Delete Date' this is intended so the user will right click on a cell and select the 'Delete Date' option on the contextmenu which will then remove the current date from the cell and leave the cell blank (no date). The problem is that I am unsure how to acheive this???

Thanks inadvance

Simon
Link Posted: 10-Oct-2005 15:26
It seems that you right click into the inplace editor area.
In this case you should right click another (not edited) cell of FlyGrid, or hide editor or turn your FlyGrid or this column into ReadOnly mode.
Link Posted: 11-Oct-2005 07:58
The problem is that, the reason why I wish to be able to display a contextmenu is because I need a way for the user to be able to quickly insert today's date and to be able to remove a date as simply as possible. The way I had thought of doing this is by using the contextmenu, but this obviously has issues.

Another way that I can think of, is if the user performs a single click in the cell then it automatically adds today's date, and then if the user performs a double click in the cell then it would removes the date. The problem is that I am unsure how to code this. Is this a possibility??? And if so would you be able to give me an example of code  

Thanks in advance

Simon
Link Posted: 11-Oct-2005 08:33
You can override Column.OnCellClick to pre-fill datta in node cell:
[C#]
public class PreFilledColumn : Column
{
  public PreFilledColumn() : base(){}
  public PreFilledColumn(string name) : base(name){}
  public PreFilledColumn(string name, string fieldName) : base(name, fieldName){}
  public override bool OnCellClick(FlyGrid grid, NodeBase node, Point clickPt)
  {
    object value = this.GetValue(node);
    if (value == null || value == System.DBNull.Value || value.Equals(string.Empty))
    {
      //pre fill cell data
      this.SetValue(node, GetPreFilledData(node));
    }
    return base.OnCellClick(grid, node, clickPt);
  }
  private object GetPreFilledData(NodeBase node)
  {
    return DateTime.Today;
  }
}


Or you can give the user possiblity to enter or cancel input of data by setup inplace editor:
[C#]
public class PreFilledColumn : Column
{
  public PreFilledColumn() : base(){}
  public PreFilledColumn(string name) : base(name){}
  public PreFilledColumn(string name, string fieldName) : base(name, fieldName){}
  protected override void OnEditorSetup(TextBox editor)
  {
     base.OnEditorSetup (editor);
     if (editor.Text == string.Empty)
     {
       //pre fill data in the inplace editor
       editor.Text = GetPreFilledData();
     }
   }
   private string GetPreFilledData()
   {
     return DateTime.Today.ToString();
   }
}
Link Posted: 13-Oct-2005 10:18
This seems ideal for what I need, but is it possible for you to please post the code again but in vb.net as I am unfamillar with C#.

Thank you

Simon
Link Posted: 13-Oct-2005 18:08
1.
[VB.Net]
Public Class PreFilledColumn
  Inherits Column

  Public Sub New(ByVal name As String)
    MyBase.New(name)
  End Sub
  
  Public Sub New(ByVal name As String, ByVal fieldName As String)
    MyBase.New(name, fieldName)
  End Sub

  Public Overrides Function OnCellClick(ByVal grid As FlyGrid, ByVal node As NodeBase, ByVal clickPt As Point) As Boolean
    Dim _value As Object = MyBase.GetValue(node)
    If (_value Is Nothing OrElse _value = DBNull.Value OrElse _value.Equals(String.Empty)) Then
      MyBase.SetValue(node, GetPreFilledData(node))
    Else
      Return MyBase.OnCellClick(grid, node, clickPt)
    End If
  End Function

  Private Function GetPreFilledData(ByVal node As NodeBase) As Object
    Return Date.Today
  End Function

End Class


2
[VB.Net]
Public Class PreFilledColumn
  Inherits Column

  Public Sub New(ByVal name As String)
    MyBase.New(name)
  End Sub
  
  Public Sub New(ByVal name As String, ByVal fieldName As String)
    MyBase.New(name, fieldName)
  End Sub

  Protected Overrides Sub OnEditorSetup(ByVal editor As TextBox)
    MyBase.OnEditorSetup(editor)
    If (editor.[Text] = String.Empty) Then
      editor.[Text] = GetPreFilledData
    End If
  End Sub

  Private Function GetPreFilledData() As String
    Dim _dateTime As Date = Date.Today
    Return _dateTime.ToString
  End Function

End Class
Link Posted: 16-Oct-2005 21:15
Thank you, that worked great

Simon