English 中文(简体)
• 输电管网点时段
原标题:winforms - gridview cell timespan edit problem
最佳回答

你们必须落实这一特点,以降低投入价值。

时间范围表可用于将受限时间Span数据转换成显示格式格式图。 但是,它可以将投入价值转换到时间范围。 您必须转换数据GridView的投入价值。 手机活动手。

下面是按投入价值分类的样本代码。

<>DataGridView.CellParsing activityhandler

private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
{
    if (e.DesiredType == typeof(TimeSpan))
    {
        TimeSpanParser parser = new TimeSpanParser();
        e.Value = parser.Parse(e.Value.ToString(), e.InheritedCellStyle.Format);
        e.ParsingApplied = true;
    }
}

www.un.org/Depts/DGACM/index_spanish.htm 时间段:

public class TimeSpanParser
{
    private Regex formatParser;

    private List<TimeSpanPart> parts;

    public TimeSpanParser()
    {
        this.formatParser = new Regex("d{1,2}|h{1,2}|m{1,2}|s{1,2}|f{1,7}", RegexOptions.Compiled);
        this.parts = new List<TimeSpanPart>();
    }

    public TimeSpan Parse(string input, string format)
    {
        this.parts.Clear();
        var pattern = this.formatParser.Replace(format, m => ReplaceFormat(m));
        var match = Regex.Match(input, "^" + pattern + "$");

        TimeSpan result = new TimeSpan();
        for (int i = 1; i < match.Groups.Count; i++)
        {
            var value = Convert.ToDouble(match.Groups[i].Value);
            switch (this.parts[i - 1])
            {
                case TimeSpanPart.Day:
                    result = result.Add(TimeSpan.FromDays(value));
                    break;
                case TimeSpanPart.Hour:
                    result = result.Add(TimeSpan.FromHours(value));
                    break;
                case TimeSpanPart.Minute:
                    result = result.Add(TimeSpan.FromMinutes(value));
                    break;
                case TimeSpanPart.Second:
                    result = result.Add(TimeSpan.FromSeconds(value));
                    break;
                case TimeSpanPart.Millisecond:
                    int digit = match.Groups[i].Value.Length;
                    value =value * Math.Pow(10, 3 - digit);
                    result = result.Add(TimeSpan.FromMilliseconds(value));
                    break;
            }
        }

        return result;
    }

    private string ReplaceFormat(Match match)
    {
        switch (match.Value)
        {
            case "dd":
            case "d":
                this.parts.Add(TimeSpanPart.Day);
                return "(\d{1,2})";
            case "hh":
            case "h":
                this.parts.Add(TimeSpanPart.Hour);
                return "(\d{1,2})";
            case "mm":
            case "m":
                this.parts.Add(TimeSpanPart.Minute);
                return "(\d{1,2})";
            case "ss":
            case "s":
                this.parts.Add(TimeSpanPart.Second);
                return "(\d{1,2})";
            case "fffffff":
            case "ffffff":
            case "fffff":
            case "ffff":
            case "fff":
            case "ff":
            case "f":
                this.parts.Add(TimeSpanPart.Millisecond);
                return "(\d{1,7})";
            default:
                return match.Value;
        }
    }
}

<>Span Part enum

public enum TimeSpanPart
{
    Day,
    Hour,
    Minute,
    Second,
    Millisecond,
}
问题回答




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.