2017-11-17 4 views
0

私のグループは、このコンボボックスとdatagridviewを互いに話すことに問題があります。起こるはずのことは、コンボボックスから名前を選択すると、技術的なIDを持つ開いているインシデントが表示されるはずです。フィルターは機能していますが、2人が互いに話すことはできません。これまでのコードは次のとおりです。コンボボックスを使用してDataGridViewに表示するデータを取得してクエリ結果をフィルタリングする

public partial class frmIncidentMaintenance : Form 
{ 
    public Incident incident; 
    public frmIncidentMaintenance() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 

     TechSupportEntities techSupport = new TechSupportEntities(); 

      var customers = (from customer in techSupport.Customers 
          orderby customer.Name 
          select new { customer.CustomerID, customer.Name 
    }).Distinct(); 
     cmbCustomersBindingSource.DataSource = customers.ToList(); 
     cmbCustomersBindingSource.DisplayMember = "Name"; 
     cmbCustomersBindingSource.ValueMember = "CustomerID"; 





     var products = from customer in techSupport.Customers 
         from incident in customer.Incidents 
         where incident.TechID != null 
         where incident.DateClosed == null 
         select new 
         { 
          incident.ProductCode, 
          incident.TechID, 
          incident.Title, 
          incident.DateOpened, 
          incident.DateClosed, 
          incident.Description 
         }; 


     dataGridView1.DataSource = products.ToList(); 


    } 

    private void cmbCustomers_SelectedIndexChanged(object sender, EventArgs 
e) 
    {     




    } 

    private void dataGridView_CellContentClick(object sender, 
DataGridViewCellEventArgs e) 
    { 

    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     this.Close(); 
     } 
    } 
} 

助けてください。あなたはcmbCustomers_SelectedIndexChangedで、いくつかのロジックを配置する必要があり

+0

、例えば、パラメータ(cmbCustomers SelectedValueのを)受け取るメソッドを作成し、その後、cmbCustomersがイベントを起動するたびにそれを呼び出します。 – JCM

+0

JCMとまったく同じですか?私と私の2人のパートナーは、2週間この作業を続けており、SelectedIndexChangedイベントハンドラに悩まされ続けています。 – Venomsamurai

答えて

0
private void cmbCustomers_SelectedIndexChanged(object sender, EventArgs 
e) 
{   
    //This is the string for your tech id 
    string tech_id = combobox.SelectedItem.ToString(); 

    //Searches the datagridview 
    int rowIndex =0; 
    foreach(DataGridViewRow row in [name of grid here]) 
    { 
     //matches tech-id to gridrow value 
     if(tech_id == row.Cells[//Cell for tech_id].Value.ToString()) 
     { 
      //Looks for open incidents (ill guess a numberical value 1 or 0 
      int open_close_value = Convert.ToInt16(row.Cells[openvalue]contains this data].value.ToString()); 
      if(open_close_value == value your looking for) 
      { 
       //rowindex will give you the row of the gridview 
       rowindex = row.Index; 
       string incident = row.Cells[you incident].Value.ToString(); 

       // for pushing data to be displayed in textboxes make it 
       // easier on yourself and allow the search engine to pull 
       //all incidents that are open with that tech_id add them to a list 
       //this will add the row number plus the incident 
       Listbox1.Items.Add(rowindex+","+incident); 

       //now on listbox1 selectedindex change all you do is parse rowindex, and use that rownumber to pull data out of database. 
       // your parse string should look like this. 
       //string[] data = listbox1.Selectedindex.ToString().Split(new string[] {","}, StringSplitOptions.None); 
       //to get data from gridview 
       //string incident= yourGrid.Rows[data[0]].Cell[the cell you want].value.ToString(); 












} 
+0

これは、技術的なIDのすべてのオープンインシデントを把握し、リストから1つを選択できるようにします。表示する。それがあなたを助けることを願っています。 –

+0

DataGridViewに同じ情報を表示する方法はありますか?特定の列の情報を変更できるようにしたい。 – Venomsamurai

+0

グリッドに追加する変数を宣言します。 GridName.Rows.Add(// variable1、variable2)を使用します。変数をグリッドの列の順に配置します。つまり、商品が列0にある場合、行を追加すると最初の変数になります。列1は2番目の列になります。等々。 add変数の代わりに –

0
private void cmbCustomers_SelectedIndexChanged(object sender, EventArgs e) 
{   
//This is the string for your tech id 
string tech_id = combobox.SelectedItem.ToString(); 

//Searches the datagridview 

foreach(DataGridViewRow row in [name of grid here]) 
{ 
    //matches tech-id to gridrow value 
    if(tech_id == row.Cells[//Cell for tech_id].Value.ToString()) 
    { 
     //Looks for open incidents (ill guess a numberical value 1 or 0 
     int open_close_value = Convert.ToInt16(row.Cells[openvalue]contains this data].value.ToString()); 
     if(open_close_value == value your looking for) 
     { 
      //rowindex will give you the row of the gridview 
      rowindex = row.Index; 
      string incident = row.Cells[you incident].Value.ToString(); 

      // for pushing data to be displayed in textboxes make it 
      // easier on yourself and allow the search engine to pull 
      //all incidents that are open with that tech_id add them to a grid 
      //this will add the row number plus the incident 
      NewGrid.Rows.Add(row.Cells[0].Value, row.Cells[1].Value,row.Cells[2].Value, row.Cells[3].Value,row.Cells[4].Value,row.Cells[5].value); 

      //now on listbox1 selectedindex change all you do is parse rowindex, and use that rownumber to pull data out of database. 
      // your parse string should look like this. 
      //string[] data = listbox1.Selectedindex.ToString().Split(new string[] {","}, StringSplitOptions.None); 
      //to get data from gridview 
      //string incident= yourGrid.Rows[data[0]].Cell[the cell you want].value.ToString(); 



} 
+0

これは、別個のグリッドビューに追加されます –

関連する問題