dev 控制項之 gridcontrid 應用

來源:互聯網
上載者:User

標籤:io   strong   資料   for   ar   log   new   ad   

一、gridview 新增一行有兩種:

   1.gridView.AddNewRow()然後在gridView_InitNewRow事件裡面填寫新添加行的資料。

     

private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e) //添加一行後觸發事件,賦值
{
    ColumnView View = sender as ColumnView;

    
    View .SetRowCellValue(e.RowHandle, "UserName", addusername);
    View .SetRowCellValue(e.RowHandle, "LoginName", addloginname);
    gridView1.FocusedRowHandle = e.RowHandle;

}

2. 直接在 資料來源裡面賦值,及datatable裡面。

datatable  table = new datatable();

gridcontrid.datasource = table;

DataRow newrow = usertable.NewRow();
newrow["UserName"] = addusername;
newrow["LoginName"] = addloginname;
usertable.Rows.Add(newrow);
gridView1.FocusedRowHandle = gridView1.RowCount - 1;

二、gridview介面上的修改刪除操作

修改:gridView1.SetFocusedRowCellValue("UserName",editForm.returuserName);

刪除:gridView1.DeleteRow(deletehandle[i]);   //刪除一行

   gridView1.DeleteSelectedRows();    //刪除選中的所有行

三 gridview屬性設定

列頭禁止移動 :  設定gridView1.OptionsCustomization.AllowColumnMoving = false;

列頭禁止排序:    設定gridView1.OptionsCustomization.AllowSort = false;.

隱藏最上面的GroupPanel  :gridView1.OptionsView.ShowGroupPanel=false;

資料唯讀  :gridView1.OptionsBehavior.Editable=false;

唯讀可拷貝:
    ColumnViewOptionsBehavior.Editable = True
    OptionsColumn.AllowEdit = True
    OptionsColumn.ReadOnly = True

 可編輯:
    ColumnViewOptionsBehavior.Editable = True
    OptionsColumn.AllowEdit = True
    OptionsColumn.ReadOnly = False

得到儲存格資料(0行0列):
   string ss=gridView1.GetRowCellDisplayText(0,gridView1.Columns[0]);
   string ss = gridView1.GetRowCellValue(0, gridView1.Columns[0]);

設定儲存格資料(將0行0列的儲存格賦值123):
   gridView1.SetRowCellValue(0, gridView1.Columns[0],"123");

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.