Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Adding of datetimepicker with code...

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

Adding of datetimepicker with code...
Link Posted: 25-Sep-2005 03:48
Could you please help, I have been trying to use your examples to acheive this, what I want is to add a date to a flygrid. I have done the code below, which does not give an error but does not display / set the date. Could you please point out what I am doing wrong???


        Dim data As Object() = New Object() {"15/10/2005", New DateTime(2005, 10, 15)}
        Me.flygrid1.Rows.Items.Add(New Node(Data))


At the moment I have added a column at design time but what I need to be able to do is create a datetime column at runtime, could you if possible provide me with a code sample in vb.net??

Thanks in advance

Simon
Link Posted: 26-Sep-2005 04:37

Private Sub InitGrid(ByVal flyGrid As FlyGrid)
  flyGrid.BeginInit()
  Try
    'clear columns
    flyGrid.Columns.Items.Clear()
    'add new columns  
    Column textCol = New Column("Text Column")
    DateTimeColumn dateCol = New DateTimeColumn("Date Column")    
    dateCol.EditorStyle = EditorStyle.DropDown
    flyGrid.Columns.Items.AddRange(new Column(){textCol, dateCol})
    'add nodes
    For i = 0 To 10
      Dim nodeData As Object() = New Object() {"15/10/2005", New DateTime(2005, 10, 15)}
      flyGrid.Rows.Items.Add(New Node(nodeData))
    Next i
  Finally
    flyGrid.EndInit()
  End Try
End Sub
Link Posted: 26-Sep-2005 07:46
Thanks for the reply.

I have however got a bit of a small problem with the code. The 3rd column will not always be a datetime column, so I have set the 3rd column to a DynamicallyAutoDetectDataTypeColumn and used the following code:-


        Dim colName As String = "name"
        Dim colDesc As String = "desc"
        Dim colvalue As Object() = New Object() {"15/10/2005", New DateTime(2005, 10, 15)}
        Dim data As Object() = New Object() {colName, colDesc, colvalue}
        Me.lstProperties.Rows.Items.Add(New Node(data))


But it displays Object[] Array in the datetime column, I obviously have done something wrong????

Also if I wanted the datetime cell to display no date but still allow the datetimepicker control to be used would I use the following code??


        Dim colvalue As Object() = New Object() {Nothing, New DateTime()}


Thanks for the help

Simon
Link Posted: 26-Sep-2005 09:10
You forget to correctly init data in the node:
Incorrect - data for the third cell are not defined

Dim colvalue As Object() = New Object() {"15/10/2005", New DateTime(2005, 10, 15)}


Correct:

Dim colvalue As Object() = New Object() {"15/10/2005", New DateTime(2005, 10, 15), "Data to display in DynamicallyAutoDetectDataTypeColumn cells"}
Link Posted: 26-Sep-2005 10:29
Thank you for the code it worked great.

Just another question, is there a way that I can add data to a specific row and column without having to format the node correctly.

i.e. if I have the following code, but I wanted to add it into the 2nd column.

Note. Not correct code just an example to try and explain


Dim nodeData As Object() = New Object() {New DateTime(2005, 10, 15)}
Me.flygrid.Row(2).column(3).Items.Add(New Node(nodeData))


Thank you again

Simon
Link Posted: 26-Sep-2005 10:55
You can modify some node cell value by following code:

Private Sub SetNewValue(ByVal col as Column, ByVal node as NodeBase, ByVal newValue as Object)
col.setValue(node, newValue)
End Sub

Or

Private Sub SetNewValue(colIndex as Integer, ByVal node as NodeBase, ByVal newValue as Object)
node.SetCellValue(colIndex, newValue);
End Sub


If you want to modify whole row - you should modify NodeBase.Value property
Link Posted: 26-Sep-2005 11:50
The only problem is that you are not able to use this if there is not currently any rows added, because it returns null ref error.

If I explain what I am trying to acheive then you might be able to suggest the best way to proceed.

I need to make it possible for the user to be able to add columns and rows to my flygrid. Adding the columns is now not a problem, thanks to your help   . The only problem I have is that I now need to enter values into specific columns and rows, but there might not even be any rows created at this point.

All the columns will be datetime. I'm sorry to keep asking questions but I can't seem to work out how to do this, and as I only purchased flygrid last week I'm still getting to grips with it.  

Thanks for your time

Simon
Link Posted: 26-Sep-2005 12:07
If columns has been added you can easily add nodes-rows (see the Best Performance VB.Net sample):
'create cell array
Dim data as Object() = New Object(flyGrid.Columns.Items.Count){}
'init array
For i as Integer = 0 To data.Length-1
data(i) = DateTime.Now
Next i
flyGrid.Rows.Items.Add(New Node(data))
Link Posted: 26-Sep-2005 12:15
Thank you that worked great.

Cheers

Simon