不一定要数据库只要是dataset或datatable都可以绑定呀

解决方案 »

  1.   

    DataGrid非要绑定个数据库才能用:(((
    这个谁说的?只要是数据就行
      

  2.   

    DataGrid 很好用啊,把数据放到DataTable里,再设置DataGrid的数据源嘛。
    private void Form1_Load(object sender, System.EventArgs e)
    {
    codeDataTable = new DataTable("CodeTable");
    codeDataTable.Columns.Add("Modifier");
    codeDataTable.Columns.Add("PropertyName");
    codeDataTable.Columns.Add("Type");
    codeDataTable.Columns.Add("Comment");
    dataGrid1.DataSource = codeDataTable;
    comboBox1.Text = comboBox1.Items[0].ToString();
    } private void dataGrid1_MouseDown(object sender, MouseEventArgs e)
    {
    DataGrid myGrid = (DataGrid) sender;
    DataGrid.HitTestInfo hitInfo = myGrid.HitTest(e.X, e.Y);
    int col = hitInfo.Column;
    int row = hitInfo.Row;
    if( hitInfo.Type == DataGrid.HitTestType.Cell )
    {
    if( row > codeDataTable.Rows.Count - 1 || ( row == 0 && codeDataTable.Rows.Count == 0) )
    {
    string[] defaultValue = {this.defaultModifier , this.defaultPropertyName , this.defalutType };
    codeDataTable.Rows.Add(defaultValue);
    myGrid.Update();
    }
    } }
      

  3.   

    哈西表作为数据源:
    Hashtable tabValues = new Hashtable(5);
    tabValues.Add("Microsoft", 49.56);
    tabValues.Add("Sun", 28.33);
    tabValues.Add("IBM", 55);
    tabValues.Add("Compaq", 20.74);
    tabValues.Add("Oracle", 41.1); // set the DataSource property of the controls // first <select> displays the Keys in the HashTable
    MySelectList1.DataSource = tabValues;
    MySelectList1.DataTextField = "Key";
    数据源为datareader:
    OleDbConnection objConnect = new OleDbConnection(strConnect); // open the connection to the database
    objConnect.Open(); // create a new Command using the connection object and select statement
    OleDbCommand objCommand = new OleDbCommand(strSelect, objConnect); // execute the SQL statement against the command to get the DataReader
    objDataReader = objCommand.ExecuteReader();
    MyDataGrid.DataSource = objDataReader;
    MyDataGrid.DataBind();
      

  4.   

    以上的代码是,点一个Cells就生成新的行。
      

  5.   

    看来楼主说的是winform的Grid,而不是webform的DataGrid
      

  6.   

    没错,我原来用Delphi的,想找一个象原来Delphi中的普通的Grid那样的控件,没想到C#里面有点复杂
      

  7.   

    DataGrid你要是用熟练的话很是好用的,他有很多的属性,你要显示就直接帮定就可以了,而且他还可以自定义显示属性,自定义模版类
    给你个例子了
    <ASP:DATAGRID id="DataGrid1" runat="server" BorderColor="#D7DFE8" BorderWidth="1px" CellPadding="1"
    Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#E7F0F9" HeaderStyle-font-weight="fold"
    AutoGenerateColumns="False" width="100%" BackColor="#ffffff" Font-Names="Verdana" AllowPaging="true"
    PageSize="15" PagerStyle-Mode="NumericPages">
    <HeaderStyle Wrap="False" CssClass="tttable" BackColor="#E7F0F9"></HeaderStyle>
    <SelectedItemStyle Wrap="False"></SelectedItemStyle>
    <EditItemStyle Wrap="False"></EditItemStyle>
    <AlternatingItemStyle Wrap="False" BackColor="#F6F6F6"></AlternatingItemStyle>
    <ItemStyle Wrap="False"></ItemStyle>
    <Columns>
    <asp:BoundColumn DataField="帮定的数据库字段" HeaderText="你想显示的字段名">
    <ItemStyle Wrap="False" Width="8%"></ItemStyle>
    </asp:BoundColumn>
    </Columns>
    </ASP:DATAGRID>
    你可以自己试着看看以上关于DataGride 各属性具体的效果
    早日进步..
      

  8.   

    哪儿有DataGrid的详细资料啊。
      

  9.   

    这里有,
    http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
    还有msdn