2017-11-17 1 views
0

내 그룹에서이 콤보 상자와 데이터 대화 뷰로 대화하는 데 문제가 있습니다. 무슨 일이 일어나기 시작했는지는 콤보 박스에서 이름을 선택하면 기술 ID가 첨부 된 공개 된 사건이 ​​나타납니다. 필터는 작동하지만 두 사람이 서로 대화 할 수는 없습니다. 지금까지 작성한 코드는 다음과 같습니다.콤보 상자를 사용하여 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(); 
     } 
    } 
} 

도움이 될만한 정보가 있습니다.

+0

당신은, 예를 들어, cmbCustomers_SelectedIndexChanged에서 약간의 논리를 넣어 매개 변수 (cmbCustomers SelectedValue)를 수신하는 방법을 확인한 다음 cmbCustomers이 이벤트를 발생 때마다 호출해야합니다. – JCM

+0

정확히 JCM을 좋아하세요? 저와 두 파트너가 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에 대해 알고있는 모든 열린 사건을 가져오고 목록에서 하나를 선택할 수 있도록합니다. 표시 할 수 있습니다. 희망이 당신을 도와줍니다. –

+0

DataGridView에 같은 정보를 표시 할 수 있습니까, Michael? 우리는 특정 열의 정보를 변경할 수 있기를 원합니다. – Venomsamurai

+0

그리드에 추가 할 변수를 선언하십시오. GridName.Rows.Add (// variable1, variable2);를 사용하십시오. 변수를 그리드의 열 순서로 배치하십시오. 즉, 제품이 열 0에 있으면 행을 추가 할 때 첫 번째 변수가됩니다. 열 1은 두 번째 열입니다. 등등. 변수 추가 대신 –

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

이것은 별도의 gridview에 추가됩니다. –

관련 문제