DataGrid    某一列如果字数太多 就会往旁边撑开来以便显示全部字数~!能不能 超出字数以后用...代替呢

解决方案 »

  1.   

    可以在数据查询语句上做手脚right([字段名],[长度])+'...'这个CSDN上已经很多人问过了
    你可以西安搜索一下帖子再说
      

  2.   

    http://topic.csdn.net/u/20080830/12/08a55ca6-184e-4296-be6a-aa92d04045ab.html这个里面你可以看看先
      

  3.   


    public const string ConstChineseRegex = @"^[\u4e00-\u9fa5]+$";
    public const string ConstEnglishRegex = @"^[a-zA-Z_0-9]+$";
    public const string ConstChineseEnglishRegex = @"^[\u4e00-\u9fa5\w]+$";
      public static bool IsChinese(string text)
            {            return System.Text.RegularExpressions.Regex.Match(text, ConstChineseRegex, System.Text.RegularExpressions.RegexOptions.Compiled).Success;
            }        public static bool IsChinese(char ch)
            {
                return IsChinese(Convert.ToString(ch));
            }        public static bool IsEnglish(string text)
            {            return System.Text.RegularExpressions.Regex.Match(text, ConstEnglishRegex, System.Text.RegularExpressions.RegexOptions.Compiled).Success;
            }        public static bool IsEnglish(char ch)
            {
                return IsEnglish(Convert.ToString(ch));
            }        public static bool IsChineseEnglish(string text)
            {            return System.Text.RegularExpressions.Regex.Match(text, ConstChineseEnglishRegex, System.Text.RegularExpressions.RegexOptions.Compiled).Success;
            }        public static bool IsChineseEnglish(char ch)
            {
                return IsChineseEnglish(Convert.ToString(ch));
            }
      public static int GetLength(string str)
            {
                int length = 0;            int countChinese = 0;
                int countEnglish = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    char ch = str[i];                if (RegexHelper.IsEnglish(ch))
                    {
                        countEnglish++;
                    }
                    else if (RegexHelper.IsChinese(ch))
                    {
                        countChinese++;
                    }
                }            length = countChinese * 2 + countEnglish;            return length;
            }        public static string SubStringReturnSameWidth(string str, int length, string endStr)
            {
                if (string.IsNullOrEmpty(str))
                {
                    return null;
                }
                if (string.IsNullOrEmpty(endStr))
                {
                    endStr = string.Empty;
                }
                string temp = str.Substring(0, (str.Length < length + 1) ? str.Length : length + 1);
                byte[] encodedBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(temp);            string outputStr = "";
                int count = 0;            for (int i = 0; i < temp.Length; i++)
                {
                    if ((int)encodedBytes[i] == 63)
                        count += 2;
                    else
                        count += 1;                if (count <= length - endStr.Length)
                        outputStr += temp.Substring(i, 1);
                    else if (count > length)
                        break;
                }            if (count <= length)
                {
                    outputStr = temp;
                    endStr = "";
                }            outputStr += endStr;            return outputStr;
            }调用示例string result=SubStringReturnSameWidth("2008奥运OK!",6,"…");//中文算2
    显示:2008奥运
      

  4.   

    获得结果集DS后不要先填充Adapter, for循环取出每行数据比如:
              for(int i = 0; i<ds.table[0].rows.count;i++)
             {
               string address =ds.table[0].rows[0]["address"].tostring();
                if(address.length>20)
                {
                   address = address.Substring(0, 20) + "...";
                   ds.Tables[0].Rows[i]["address"] = address;
                }
             }
    最后填充,然后绑定!
      

  5.   


        ///   <summary>  
        ///   截取字符串(适用于中英文混合)  
        ///   </summary>  
        ///   <param   name="str">原字符串</param>  
        ///   <param   name="len">长度</param>  
        ///   <returns></returns>  
        public static string CutString(string str, int len)
        {
            str = str.Trim();
            byte[] myByte = System.Text.Encoding.Default.GetBytes(str);
            if (myByte.Length > len)
            {
                string result = "";
                for (int i = 0; i < str.Length; i++)
                {
                    byte[] tempByte = System.Text.Encoding.Default.GetBytes(result);
                    if (tempByte.Length < len)
                    {
                        result += str.Substring(i, 1);
                    }
                    else
                    {
                        break;
                    }
                }
                return result + "...";
            }
            else
            {
                return str;
            }
        }
    试试这个