問題是,當它綁定到StringCollection
時,基礎類型爲string
,因此它將從找到的類型string
中抽出第一個屬性來顯示。該屬性是長度。
你可以做的是將你的StringCollection
包裝在你自己製作的類中,並公開一個屬性來顯示string
的文本。爲string
包裝類:
public class MyString
{
private string _myString;
public string Text
{
get { return _myString; }
set { _myString = value; }
}
public MyString(string str)
{
_myString = str;
}
}
您的代碼就變成了:
StringCollection dict = Settings.Default.MyDict;
// put your string in the wrapper
List<MyString> anotherdict = new List<MyString>();
foreach (string str in dict)
{
anotherdict.Add(new MyString(str));
}
BindingSource bs = new BindingSource();
// bind to the new wrapper class
bs.DataSource = anotherdict;
this.DGV.DataSource = bs;
的 可能的複製http://stackoverflow.com/questions/1104341/net-c-sharp-binding -iliststring-to-a-datagridview – Markissimo 2012-04-13 12:23:27
它不是重複的,它的.net2.0 – Habib 2012-04-13 12:39:16