如果你的typeID是整整下面就是用int,如果是字符或其它類型就用其它,0表示ds中的第一列,如果第二列就依次增加1
dataGrid1.DataSource=ds.Tables["DataTable _a"];
int typeid = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex,0].ToString());
DataView dv = ds.Tables["DataTable _b"].DefaultView
dv.RowFilter = "TypeID = "+typeid.ToString();
dataGrid2.DataSource = dv;

解决方案 »

  1.   

    ///这里给出一个相似的例子。
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.OleDb;namespace useDataGrid
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
            private System.Windows.Forms.DataGrid dataGrid1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    //
    } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
                this.dataGrid1 = new System.Windows.Forms.DataGrid();
                ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
                this.SuspendLayout();
                // 
                // dataGrid1
                // 
                this.dataGrid1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                    | System.Windows.Forms.AnchorStyles.Left) 
                    | System.Windows.Forms.AnchorStyles.Right);
                this.dataGrid1.DataMember = "";
                this.dataGrid1.Name = "dataGrid1";
                this.dataGrid1.Size = new System.Drawing.Size(312, 264);
                this.dataGrid1.TabIndex = 0;
                // 
                // Form1
                // 
                this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
                this.ClientSize = new System.Drawing.Size(312, 269);
                this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                              this.dataGrid1});
                this.Name = "Form1";
                this.Text = "使用DataGrid控件来显示数据";
                this.Load += new System.EventHandler(this.Form1_Load);
                ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
                this.ResumeLayout(false);        }
    #endregion /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }        private void Form1_Load(object sender, System.EventArgs e)
            {
                string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mctest.mdb";             // 实例化OleDbConnection对象
                OleDbConnection myConnection = new OleDbConnection(); 
                myConnection.ConnectionString = connString;            // 实例化OleDbDataAdapter对象
                OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Developer", myConnection); 
                
                // 实例化DataSet对象
                DataSet ds = new DataSet(); 
                
                // 把表中的数据填到DataSet对象中
                da.Fill(ds, "Developer");
                
                // 把数据显示在DataGrid控件中
                dataGrid1.DataSource = ds.DefaultViewManager; 
            }
    }
    }