2017-03-16 93 views
-1

我設計了一個grid control 20行3列。 在第一列中我已經輸入了一些硬編碼的字符串,在第二列中,我想將checkBox與選中的未檢查行爲相關聯,以便用戶可以對其進行修改。我在下面的代碼中爲QueryCellInfo事件編寫了代碼,但它不起作用。如何使CheckBox選中或取消選中,以便用戶可以在Grid Control中對其進行修改?

我該如何完成它?

請提出建議。

下面是我的代碼部分:

public partial class Form1 : Form 
{ 
    System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer(); 
    private Syncfusion.Windows.Forms.Grid.GridControl gridControlDownloadScript = new Syncfusion.Windows.Forms.Grid.GridControl(); 
    public Form1() 
    { 
     // this.gridControl1.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro; 
     InitializeComponent(); 

    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 

     gridControl1.Model.RowCount = 20; 
     gridControl1.Model.ColCount = 3; 
     this.gridControl1.VScrollPixel = true; 
     this.gridControl1.HScrollPixel = true; 


     this.gridControl1[0, 1].Text = "EMPLOYEE"; 
     this.gridControl1[0, 2].Text = "CHECKBOX"; 
     this.gridControl1[0, 3].Text = " "; 
     this.gridControl1[1, 1].Text = "Rahul Verma"; 
     this.gridControl1[2, 1].Text = "MAnish Desai"; 
     this.gridControl1[3, 1].Text = "Mohan Pothala"; 
     this.gridControl1[4, 1].Text = "Dhanraj Dhoke"; 

     gridControl1.Model.RowCount = 20; 

     gridControl1.Model.ColCount = 3; 
     gridControl1.QueryCellInfo += new GridQueryCellInfoEventHandler(GridQueryCellInfo); 
     gridControl1.SaveCellInfo += new GridSaveCellInfoEventHandler(GridSaveCellInfo); 
     gridControl1.QueryRowCount += gridControl1_QueryRowCount; 
     gridControl1.QueryColCount += gridControl1_QueryColCount; 
     this.gridControl1.HScrollBehavior = GridScrollbarMode.Disabled; 
     this.gridControl1.VScrollBehavior = GridScrollbarMode.Disabled; 

     this.gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Cols(1, 1)); 

     this.gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Rows(1, 20)); 


     t1.Interval = 250; 

     t1.Tick += new EventHandler(IncreaseProgressBar); 



    } 

    private void CellClick(object sender, GridCellClickEventArgs e) 
    { 
    } 



    private void IncreaseProgressBar(object sender, EventArgs e) 
    { 
     progressBar1.Increment(5); 
     progressBar1.Minimum = 0; 
     progressBar1.Maximum = 100; 


     lblProgress.Text = progressBar1.Value.ToString() + "%"; 

     if (progressBar1.Value == progressBar1.Maximum) 

      t1.Stop(); 
    } 

    private void gridControl1_QueryColCount(object sender, GridRowColCountEventArgs e) 
    { 

    } 

    private void gridControl1_QueryRowCount(object sender, GridRowColCountEventArgs e) 
    { 

    } 

    private void GridQueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
    { 
     int i = 0; 
     while (i++ < 4) 
     { 
      if (i == 0 || i == 1 || i == 4 || i == 6 || i == 9 || i == 11 || i == 14) 
      { 

       continue; 

      } 
      else if (e.RowIndex == i && e.ColIndex == 2) 
      { 

       e.Style.CellType = GridCellTypeName.CheckBox; 

       e.Style.Description = ""; 
     this.gridControl1[i, 2].CheckBoxOptions = new GridCheckBoxCellInfo("True", "False", string.Empty, false); 
       e.Style.CheckBoxOptions.CheckedValue = "true"; 
       e.Style.CellValue = "true"; 

      } 

     } 
     if (e.RowIndex > 0 && e.ColIndex > 0) 
     { 


     } 
    } 
+0

您使用的是什麼技術?贏表格? WPF?此外,您只是想讓用戶修改它們的「按需」是什麼意思? – Emad

+0

@Emad,我正在使用win forms.yes,我希望用戶修改它們。 對不起。 –

回答

0

您可以手動執行此操作使用網格屬性定義手動設置爲複選框列列的屬性,然後它會表現爲你想

0

QueryCellInfo事件將觸發單元GridControl。根據您的代碼,您在QueryCellInfo事​​件中將單元格值設置爲true。因此,CellValue複選框將始終保持爲真。如果您希望用戶修改CheckedValue,請在Form_Load()方法中將該特定單元的CellValue設置爲「True」。請參考下面的代碼, 代碼片段 this.gridControl1 [2,2] .CellValue =「True」; this.gridControl1 [3,2] .CellValue =「True」;

Screenshot Sample Link

注意 如果您有關於Syncfusion控制任何其他疑問,請考慮創建一個support ticketposting in the forums

相關問題