2011-12-23 30 views
1

實際上,我已經在DataGridView_CellContentClick上觸發了一個事件,它執行與datagridview有關的操作,例如更改單元格的值。但是在執行此操作之前,我想對其他控件(即ListView)上的另一個操作進行更改(或觸發)。但這並未消失雖然我在datagridview的操作之前放置了另一個操作。任何人都請幫助我。如何在執行DataGridView_CellContentClick時觸發另一個控件的事件?

而且我的代碼是這樣的: -

private void dGridDeviceList_CellContentClick(object sender, DataGridViewCellEventArgs e) 
    { 
     //DataGridViewCell dcell = dGridDeviceList.Rows[e.RowIndex].Cells[e.ColumnIndex]; 
     if (e.RowIndex >= 0) 
     { 
      ListViewItem litem1 = lvInformation.Items.Add("101"); 

      litem1.SubItems.Add(string.Empty); 
      litem1.SubItems[1].Text = "Connected."; 

      ListViewItem litem5= lvErrorList.Items.Add("check "); 
      Cursor = Cursors.WaitCursor; 
      List<cException> cxp = new List<cException>(); 
      cDeviceModel cdm = new cDeviceModel(); 
      ListViewItem litem = new ListViewItem(); 
      DataGridViewRow drow = new DataGridViewRow(); 
      cDeviceUtility cUtil = new cDeviceUtility(); 
      List<cAction> catn = new List<cAction>(); 
      drow = dGridDeviceList.Rows[e.RowIndex]; 
      cdm = (cDeviceModel)drow.Tag; 
      if (e.ColumnIndex == 6) 
      { 

       if (dGridDeviceList.CurrentCell.Value.ToString() == "Connect") 
       { 
        litem1= lvInformation.Items.Add("101"); 

        litem1.SubItems.Add(string.Empty); 
        litem1.SubItems[1].Text = "Connected."; 

        //lvInformation.Items.Insert(0, "101"); 
        //lvInformation.Items[0].SubItems.Add("Connected"); 
       } 
       // connect disconnect button column 
       if (cdm.IsConnected) 
       { 
        ListViewItem litem2 = lvInformation.Items.Add("102"); 

        litem2.SubItems.Add(string.Empty); 
        litem2.SubItems[1].Text =string.Format("Disconnecting from {0} device.",dGridDeviceList.CurrentRow.Cells["colDeviceName"].Value); 

        // then disconnect the device 
        cdm.IsConnected = false; 
        cdm.DeviceInterface.Disconnect(); 
        dGridDeviceList.Rows[e.RowIndex].Tag = cdm; 
        dGridDeviceList.Rows[e.RowIndex].Cells[6].Value = "Connect"; 
        dGridDeviceList.Rows[e.RowIndex].Cells[1].Value = img16x16.Images["notconnected"]; 
        dGridDeviceList.Rows[e.RowIndex].Cells[8].Value= 0; 
        dGridDeviceList.Rows[e.RowIndex].Cells[8].Tag = "Not Connected"; 
        dGridDeviceList.Refresh(); 
        litem2 = lvInformation.Items.Add("103"); 
        litem2.SubItems.Add(string.Empty); 
        litem2.SubItems[1].Text = string.Format("Disconnected from {0} device.", dGridDeviceList.CurrentRow.Cells["colDeviceName"].Value); 
       } 
       else 
       { 
        // string test = lvInformation.Items[0].SubItems[1].ToString(); 
        // catn.Add(new cAction { Number = lvInformation.Items.Count+1, Message = string.Format("Trying to connect with {0}", dGridDeviceList.Rows[e.RowIndex].Cells["colDeviceName"].Value) }); 
        //// lvInformation.Items.Clear(); 
        // foreach (cAction Actn in catn) 
        // { 
        // litem=lvInformation.Items.Insert(0, (lvInformation.Items.Count + 1).ToString()); 
        // litem.SubItems.Add(catn[catn.Count -1].Message); 
        // } 
        // then connect the device 
        if (!ConnectToDevice(ref drow, out cxp) == true) 
        { 
         foreach (cException err in cxp) 
         { 
          litem = lvErrorList.Items.Insert(0, err.Number.ToString()); 
          if (err.EType == ErrorType.Error) 
          { 
           litem.ImageKey = "error"; 
          } 
          else if (err.EType == ErrorType.Warning) 
          { 
           litem.ImageKey = "warning"; 
          } 
          else if (err.EType == ErrorType.Information) 
          { 
           litem.ImageKey = "information"; 
          } 
          litem.SubItems.Add(err.Message); 
          litem.SubItems.Add(err.Source); 
         } 
        } 
        else 
        { 
         dGridDeviceList.Rows[e.RowIndex].Cells[0].Value = true; 
         dGridDeviceList.Rows[e.RowIndex].Tag = drow.Tag; 
         dGridDeviceList.Rows[e.RowIndex].Cells[6].Value = "Disconnect"; 
         dGridDeviceList.Rows[e.RowIndex].Cells[1].Value = img16x16.Images["connected"]; 
         dGridDeviceList.Rows[e.RowIndex].Cells[8].Value = 0; 
         dGridDeviceList.Rows[e.RowIndex].Cells[8].Tag = "Ready"; 
         dGridDeviceList.Refresh(); 
         RemoveSelectionRow(); 
        } 
       } 
      } 
      else if (e.ColumnIndex == 7) 
      { 
       // view logs button column 
       pbarMain.Value = 100; 
       ViewLogs(dGridDeviceList.Rows[e.RowIndex],ref lvAttnLog ,ref lvErrorList); 
      } 
      Cursor = Cursors.Arrow; 
     } 
    } 
+0

我想你忘記發佈代碼 – V4Vendetta

回答

1

考慮到這是WinForm的

private void buttonCopyContent_Click(object sender, EventArgs e) 
{ 
//do something 
} 

您可以通過下面的行調用此事件 this.Invoke(new EventHandler(buttonCopyContent_Click));

+0

實際上它是在執行DataGridView的操作後發生的劇照。 –

+0

??沒有得到那 –

+0

我稱this.Invoke(新的EventHandler(buttonCopyContent_Click));在DataGridView Cellcontentclick下,它仍然在DataGridViewCellcontentClick事件完成後發生。 –

相關問題