數據庫存中表的值為1803(字符串格式),要在DataGridTextBoxColumn列中將值由1803顯示成18:03格式,輸入時不需要輸入":"分隔符,並且保存時值中不能有":"分隔符.
請問,這個格式該如何設置,或者其它的方法.
用戶沒法接受1803的輸入格式,因為舊系統中pb的,可以設置成18:03的格式,但在C#的DataGridTextBoxColumn.Format中該如何設置呀?
我另外發了兩個貼子:
http://community.csdn.net/Expert/topic/5441/5441759.xml?temp=.1754419
http://community.csdn.net/Expert/topic/5445/5445199.xml?temp=.939831
始終沒有得到解決的方法.
如果有回複,請順便在另外兩貼回一下,以好給分.謝謝啦

解决方案 »

  1.   

    格式都是一样的么?即:前两位是分钟,后两位是秒如果你有实体类的话可以在实体类中重写一下tostring()方法.如果没有作实体类那就写一个方法public string StringToMyTime(string myTime)
    {
      return myTime.substring(0,2)+":"+myTime.substring(2,2);
    }
      

  2.   

    Dim myDouble As Double = 1234567890 
    Dim myString As String = myDouble.ToString( "(###) ### - ####" ) 
      

  3.   

    int url = 1806;
         
            this.Label1.Text=url.ToString("##:##");
    这个好使,我试过了
      

  4.   

    来晚了~`
    楼上的那样可以
    .ToString("##:##");
      

  5.   

    抱歉,昨天沒有上網,不知道各位的回複.
    我想說明一點是的:
    1.DataGridTextBoxColumn綁定列的類型是字符型
    2.是DataGridTextBoxColumn的Format屬性該如何設置,或者是在DataGrid中如何控件1806顯示和輸入時為18:06的格式,而不是ToString()方法.
      

  6.   

    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                this.dataGridView1.Rows.Add("1083");
                this.dataGridView1.Columns[0].DefaultCellStyle.FormatProvider = new fmt();
            }
        }    public class fmt : IFormatProvider, ICustomFormatter
        {
            #region IFormatProvider Members        public object GetFormat(Type formatType)
            {
                if (argType == typeof(ICustomFormatter))
                    return this;
                else
                    return null;
            }        #endregion        #region ICustomFormatter Members        public string Format(string format, object arg, IFormatProvider formatProvider)
            {
                //这里写上你自己的格式化代码
            }        #endregion
        }
    }这样就可以了!
      

  7.   

    this.dataGridTextBoxColumn1.FormatInfo =new fmt();
    具体的还是去多看看MSDN!
      

  8.   

    fxqyyzg(海冬青)(昨夜西风凋碧树。独上高楼,望尽天涯路)正解!!!
    我几乎每天能看到这个名字N次  强人啊
      

  9.   

    给你的自定义控件加个属性啊,或者修改一下他的text属性.格式为##:##...显示的时候让他自然显示就行了.
      

  10.   

    public class fmt : IFormatProvider, ICustomFormatter
        {
            #region IFormatProvider Members        public object GetFormat(Type formatType)
            {
                if (argType == typeof(ICustomFormatter))
                    return this;
                else
                    return null;
            }        #endregion        #region ICustomFormatter Members        public string Format(string format, object arg, IFormatProvider formatProvider)
            {
                //这里写上你自己的格式化代码
            }        #endregion
        }this.dataGridTextBoxColumn1.FormatInfo =new fmt();
      

  11.   

    方法很多了,还可以使用"1803".Insert(2, ":")
      

  12.   

    this.dataGridTextBoxColumn1.Format="##:##";
    靠,原来就是这么简单!!!
    楼主可以结贴了!