This is a migrated thread and some comments may be shown as answers.

Hi Emanuel

3 Answers 175 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tooraj
Top achievements
Rank 1
Tooraj asked on 24 Oct 2010, 12:35 PM
Hi Emanuel, Are you working on my FADatePicker? If yes, let me know.

3 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 24 Oct 2010, 06:12 PM
Hello Tooraj,

Yes, and i have some questions, do you want the FA datetime picker element to be always visible or just in edit mode?
In normal mode can you use a normal GridViewDateTime column with a custom format?

Best Regards,
Emanuel Varga
0
Emanuel Varga
Top achievements
Rank 1
answered on 24 Oct 2010, 07:26 PM
Hello again Tooraj,

Can you please try this:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using FarsiLibrary.Win.Controls;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using System.Security.Cryptography;
using System.Text;
 
public partial class Form1 : Form
{
    private RadGridView radGridView1;
    public Form1()
    {
        InitializeComponent();
        this.Size = new System.Drawing.Size(500, 300);
        LoadGrid();
    }
 
    private void LoadGrid()
    {
        this.Controls.Add(radGridView1 = new RadGridView());
        radGridView1.Dock = DockStyle.Fill;
        radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        radGridView1.CellBeginEdit += new GridViewCellCancelEventHandler(radGridView1_CellBeginEdit);
        radGridView1.CellEndEdit += new GridViewCellEventHandler(radGridView1_CellEndEdit);
        radGridView1.DataSource = new TestsCollection(10);
    }
 
    void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
    {
        if (radGridView1.Columns[e.ColumnIndex].Name == "Date")
        {
            if (this.radGridView1.CurrentCell.Children.Count == 1)
            {
                 
                this.radGridView1.CurrentCell.Children.RemoveAt(0);
            }
        
    }
 
    void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
    {
        if (radGridView1.Columns[e.ColumnIndex].Name == "Date")
        {
            var activeEditor = radGridView1.ActiveEditor as RadDateTimeEditor;
             
            FADatePicker dateTimePicker = new FADatePicker();
            dateTimePicker.SelectedDateTimeChanged += delegate { activeEditor.Value = dateTimePicker.SelectedDateTime; };
            dateTimePicker.SelectedDateTime = (DateTime)activeEditor.Value;
            RadHostItem item = new RadHostItem(dateTimePicker);
            this.radGridView1.CurrentCell.Children.Add(item);
        
 
 
    }
}
 
#region Helpers
 
internal class Test
{
    public int Id { get; set; }
 
    public string Name { get; set; }
 
    public DateTime Date { get; set; }
 
    public Test(int id, string name, DateTime date)
    {
        this.Id = id;
        this.Name = name;
        this.Date = date;
    }
}
 
internal class TestsCollection : BindingList<Test>
{
    public TestsCollection(int noItems)
    {
        for (int i = 0; i < noItems; i++)
        {
            this.Add(new Test(i, "item" + i, DateTime.Now.AddDays(i)));
        }
    }
}
 
#endregion Helpers

I didn't change the default date format in this example but i think you can manage that, but for editing the FADatePicker is used, please let me know if this is ok for you.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Emanuel Varga
Top achievements
Rank 1
answered on 25 Oct 2010, 02:08 PM
Hello again,

I was just wondering if you had the chance to test the code in my previous post?
Did it solve your problems?

Best Regards,
Emanuel Varga
Tags
GridView
Asked by
Tooraj
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or