L?I: B?n khng th? xo m?t Excel danh sch hng t? s? ki?n CommandButton Click

D?ch tiu ? D?ch tiu ?
ID c?a bi: 823988 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TRI?U CH?NG

B?n c xy d?ng m?t ph?n m? r?ng ?c qu?n l? m? cho Office Excel 2003. Gi?i php c?a b?n s? d?ng cc Nh?p vo s? ki?n c?a m?t MSForms CommandButton i?u khi?n ? lo?i b? hng t? m?t Danh sch ?i t?ng n?m trn m?t b?ng tnh. Khi b?n nh?n nt ? lo?i b? cc Danh sch hng, hng khng ?c c?t b?, v b?n c th? nh?n ?c m?t l?i th?i gian ch?y.

T?NH TR?NG

Microsoft ? xc nh?n r?ng y l m?t l?i trong Office Excel 2003.

GI?I PHP

? gi?i quy?t v?n ? ny, h?y ch?c ch?n r?ng CommandButton khng c s? t?p trung khi b?n xo hng danh sch. S? d?ng m?t trong nh?ng phng php sau y:
  • ?t cc TakeFocusOnClick ti s?n c?a CommandButton ? sai.

    - hay -
  • Re-select ch?n b?ng tnh hi?n th?i ? c tr?ng tm t? CommandButton.

CCH GI?I QUY?T KHC

? lm vi?c xung quanh v?n ? ny, s? d?ng m?t trong nh?ng phng php sau y:
  • ?t cc TakeFocusOnClick b?t ?ng s?n cho cc CommandButton ki?m sot ? sai:
    protected void ThisWorkbook_Open()
    {
    	//Get a reference to the first worksheet.
    	ws = (Excel.Worksheet)(ThisWorkbook.Worksheets[1]);
    
    	//Set up the Click event handler for CommandButton1.
    	cb = (MSForms.CommandButton)(this.FindControl("CommandButton1"));
    	cb.Click+= new MSForms.CommandButtonEvents_ClickEventHandler(cbClick);
    
    	cb.TakeFocusOnClick = false;
    }
    


    - hay -
  • G?i cho cc Ch?n phng php cho b?ng tnh hi?n t?i L?a ch?n ? lo?i b? t?p trung t? cc CommandButton:
    private void cbClick()
    { 
    	ThisApplication.Selection.GetType().InvokeMember("Select",
    		System.Reflection.BindingFlags.Public | 
    		System.Reflection.BindingFlags.InvokeMethod | 
    		System.Reflection.BindingFlags.Instance,
    		null,
    		ThisApplication.Selection,
    		null);
    	
    	ws.ListObjects[1].ListRows[1].Delete();
    }
    

THNG TIN THM

Cc b?c ? t?o l?i hnh vi

  1. B?t ?u Microsoft Visual Studio.NET 2003.
  2. Trn cc Tp tr?nh n, i?m ?n M?i, sau b?m D an.
  3. Trong danh sch cc lo?i d? n, m? r?ng Cc d? n h? th?ng Microsoft Office, sau b?m Visual C# cc d? n. Ch?n Excel Workbook trong danh sch m?u, v sau nh?p vo Ok.
  4. Nh?p vo K?t thc trong cc Microsoft Office Project Wizard.
  5. B?m phm F5 ? ch?y cc d? n v m? b?ng tnh trong Excel.
  6. S?a ?i b?ng tnh nh sau:
    1. Ch?n A1.
    2. Trn cc D? li?u tr?nh n, i?m ?n Danh sch, sau b?m T?o danh sch. Cc T?o danh sch h?p tho?i s? xu?t hi?n. Nh?p vo Ok.
    3. Thm b?t k? vn b?n vo cc t? bo A2, A3 v A4 (A2:A4).
    4. Trn cc Xem tr?nh n, i?m ?n Thanh cng c?, sau b?m H?p cng c? ki?m sot.
    5. V? m?t CommandButton i?u khi?n trn b?ng tnh. Tn m?c ?nh l CommandButton1.
    6. Lu b?ng tnh, v sau b? Excel.
  7. Thm m? sau vo cc m-un m? Thisworkbook.cs:
    private MSForms.CommandButton cb;
    private Excel.Worksheet ws;
    
    protected void ThisWorkbook_Open()
    {
    	//Get a reference to the first worksheet.
    	ws = (Excel.Worksheet)(ThisWorkbook.Worksheets[1]);
    
    	//Set up the Click event handler for CommandButton1.
    	cb = (MSForms.CommandButton)(this.FindControl("CommandButton1"));
    	cb.Click+= new MSForms.CommandButtonEvents_ClickEventHandler(cbClick);
    }
    
    private void cbClick()
    {
    	try
    	{
    		//Delete the first row in the list object.
    		ws.ListObjects[1].ListRows[1].Delete();
    	}
    	catch (Exception ex)
    	{
    		System.Diagnostics.Debug.WriteLine(ex.Message);
    		MessageBox.Show(ex.Message);
    	}
    }
    
  8. B?m phm F5 ? xy d?ng v ch?y cc d? n.
  9. Nh?p vo CommandButton1.

    Kt qua M?t ngo?i l? b?t g?p khi xa hng trong danh sch. B?n nh?n ?c thng bo l?i sau
    Ngo?i l? t? HRESULT: 0x800A03EC

Thu?c tnh

ID c?a bi: 823988 - L?n xem xt sau cng: 28 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Visual Studio Tools for the Microsoft Office System version 2003
T? kha:
kbbug kbautomation kbnofix kbmt KB823988 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:823988

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com