首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WPF中DataGrid绑定List<T>如何没成功

2012-09-03 
WPF中DataGrid绑定ListT怎么没成功?C# codenamespace XXXXX{struct sREG{public DateTime REGDatetimep

WPF中DataGrid绑定List<T>怎么没成功?

C# code
namespace XXXXX{    struct sREG     {        public DateTime REGDatetime;        public string REGENo;        public string EName;        public bool REGRed;        public string REGStyle;        public double REGCost;    }    public partial class REquipmentG : Window    {        List<sREG> _listREG = new List<sREG>();        //………………………………        //………………………………        //………………………………        //初始化DataGrid的函数        private bool InitialDataGrid()        {            try            {                SqlDataReader reader = null;                //CommonFunction.SQLSearch此函数返回个Reader                CommonFunction.SQLSearch("select REGDatetime,REGENo,EName,REGRed,REGStyle,REGCost from tEquipments,tREG where tREG.REGENo=tEquipments.ENo", ref MainWindow._cnn, ref reader);                while (reader.Read())                {                    sREG tempsREG = new sREG();                    tempsREG.REGDatetime = Convert.ToDateTime(reader[0]);                    tempsREG.REGENo = Convert.ToString(reader[1]);                    tempsREG.EName = Convert.ToString(reader[2]);                    tempsREG.REGRed = Convert.ToBoolean(reader[3]);                    tempsREG.REGStyle = Convert.ToString(reader[4]);                    tempsREG.REGCost = Convert.ToDouble(reader[5]);                    _listREG.Add(tempsREG);                }                dgMain.ItemsSource = _listREG;            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);                return false;            }            //MessageBox.Show(_listREG[0].EName);            return true;        }   }}


XML code
    <Canvas >        <DataGrid x:Name="dgMain" Width="400" Height="300"/>    </Canvas>


为什么DataGrid什么内容页不显示?

[解决办法]
struct sREG 
{
public DateTime REGDatetime;
public string REGENo;
public string EName;
public bool REGRed;
public string REGStyle;
public double REGCost;
}

绑定只对属性有效,都改成属性

热点排行