欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
DataGridView 操作
DataGridView
2007-04-20 17:27

DataGridView   取得或者修改當前單元格的內容:

當前單元格指的是 DataGridView 焦點(diǎn)所在的單元格,它可以通過(guò) DataGridView 對象的 CurrentCell 屬性取得。如果當前單元格不存在的時(shí)候,返回Nothing(C#是null)

[VB.NET]
取得當前單元格內容
Console.WriteLine(DataGridView1.CurrentCell.Value)
取得當前單元格的列 Index
Console.WriteLine(DataGridView1.CurrentCell.ColumnIndex)
取得當前單元格的行 Index
Console.WriteLine(DataGridView1.CurrentCell.RowIndex)

[C#]
// 取得當前單元格內容
Console.WriteLine(DataGridView1.CurrentCell.Value);
// 取得當前單元格的列 Index
Console.WriteLine(DataGridView1.CurrentCell.ColumnIndex);
// 取得當前單元格的行 Index
Console.WriteLine(DataGridView1.CurrentCell.RowIndex);

 


另外,使用 DataGridView.CurrentCellAddress 屬性(而不是直接訪(fǎng)問(wèn)單元格)來(lái)確定單元格所在的行:DataGridView.CurrentCellAddress.Y 和列: DataGridView.CurrentCellAddress.X 。這對于避免取消共享行的共享非常有用。

當前的單元格可以通過(guò)設定 DataGridView 對象的 CurrentCell 來(lái)改變??梢酝ㄟ^(guò) CurrentCell 來(lái)設定
DataGridView 的激活單元格。將 CurrentCell 設為 Nothing(null) 可以取消激活的單元格。

[VB.NET]
設定 (0, 0)   為當前單元格
DataGridView1.CurrentCell = DataGridView1(0, 0)

[C#]
// 設定 (0, 0)   為當前單元格
DataGridView1.CurrentCell = DataGridView1[0, 0];


在整行選中模式開(kāi)啟時(shí),你也可以通過(guò) CurrentCell 來(lái)設定選定行。

        /**//// <summary>
        
/// 向下遍歷
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>

        private void button4_Click(object sender, EventArgs e)
        
...{
            
int row = this.dataGridView1.CurrentRow.Index + 1;
            
if (row > this.dataGridView1.RowCount - 1)
                 row
= 0;
            
this.dataGridView1.CurrentCell = this.dataGridView1[0, row];  
         }


        
/**//// <summary>
        
/// 向上遍歷
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>

        private void button5_Click(object sender, EventArgs e)
        
...{
            
int row = this.dataGridView1.CurrentRow.Index - 1;
            
if (row < 0)
                 row
= this.dataGridView1.RowCount - 1;
            
this.dataGridView1.CurrentCell = this.dataGridView1[0, row];  
         }


* 注意: this.dataGridView 的索引器的參數是: columnIndex, rowIndex 或是 columnName, rowIndex
這與習慣不同。


DataGridView   設定單元格只讀:

1) 使用 ReadOnly 屬性
⇒ 如果希望,DataGridView 內所有單元格都不可編輯, 那么只要:

[VB.NET]
設置 DataGridView1 為只讀
DataGridView1.ReadOnly = True


[C#]
// 設置 DataGridView1 為只讀
DataGridView1.ReadOnly = true;

此時(shí),用戶(hù)的新增行操作和刪除行操作也被屏蔽了。

⇒ 如果希望,DataGridView 內某個(gè)單元格不可編輯, 那么只要:

[VB.NET]
設置 DataGridView1 的第2列整列單元格為只讀
DataGridView1.Columns(1).ReadOnly = True

設置 DataGridView1 的第3行整行單元格為只讀
DataGridView1.Rows(2).ReadOnly = True

設置 DataGridView1 的[0,0]單元格為只讀
DataGridView1(0, 0).ReadOnly = True


[C#]
// 設置 DataGridView1 的第2列整列單元格為只讀
DataGridView1.Columns[1].ReadOnly = true;

// 設置 DataGridView1 的第3行整行單元格為只讀
DataGridView1.Rows[2].ReadOnly = true;

// 設置 DataGridView1 的[0,0]單元格為只讀
DataGridView1[0, 0].ReadOnly = true;


2) 使用 EditMode 屬性
DataGridView.EditMode 屬性被設置為 DataGridViewEditMode.EditProgrammatically 時(shí),用戶(hù)就不能手動(dòng)編輯單元格的內容了。但是可以通過(guò)程序,調用 DataGridView.BeginEdit 方法,使單元格進(jìn)入編輯模式進(jìn)行編輯。

[VB.NET]
DataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically

 

[C#]
DataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;


3) 根據條件設定單元格的不可編輯狀態(tài)
當一個(gè)一個(gè)的通過(guò)單元格坐標設定單元格 ReadOnly 屬性的方法太麻煩的時(shí)候,你可以通過(guò) CellBeginEdit 事件來(lái)取消單元格的編輯。

[VB.NET]
CellBeginEdit 事件處理方法
Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, _
        
ByVal e As DataGridViewCellCancelEventArgs) _
        
Handles DataGridView1.CellBeginEdit
    
Dim dgv As DataGridView = CType(sender, DataGridView)
    
是否可以進(jìn)行編輯的條件檢查
    If dgv.Columns(e.ColumnIndex).Name = "Column1" AndAlso _
        
Not CBool(dgv("Column2", e.RowIndex).Value) Then
        
取消編輯
         e.Cancel = True
    
End If
End Sub

 

[C#]
// CellBeginEdit 事件處理方法
private void DataGridView1_CellBeginEdit(object sender,
     DataGridViewCellCancelEventArgs e)
{
     DataGridView dgv
= (DataGridView)sender;
    
//是否可以進(jìn)行編輯的條件檢查
    if (dgv.Columns[e.ColumnIndex].Name == "Column1" &&
        
!(bool)dgv["Column2", e.RowIndex].Value)
     {
        
// 取消編輯
         e.Cancel = true;
     }
}


 

DataGridView   不顯示最下面的新行:

通常 DataGridView 的最下面一行是用戶(hù)新追加的行(行頭顯示 * )。如果不想讓用戶(hù)新追加行即不想顯示該新行,可以將 DataGridView 對象的 AllowUserToAddRows 屬性設置為 False。

[VB.NET]
設置用戶(hù)不能手動(dòng)給 DataGridView1 添加新行
DataGridView1.AllowUserToAddRows = False

 

[C#]
// 設置用戶(hù)不能手動(dòng)給 DataGridView1 添加新行
DataGridView1.AllowUserToAddRows = false;

但是,可以通過(guò)程序: DataGridViewRowCollection.Add 為 DataGridView 追加新行。

補足: 如果 DataGridView 的 DataSource 綁定的是 DataView, 還可以通過(guò)設置 DataView.AllowAdd
屬性為 False 來(lái)達到同樣的效果。


 

DataGridView   查找新行:

DataGridView的AllowUserToAddRows屬性為T(mén)rue時(shí)也就是允許用戶(hù)追加新行的場(chǎng)合下,DataGridView的最后一行就是新追加的行(*行)。使用 DataGridViewRow.IsNewRow 屬性可以判斷哪一行是新追加的行。另外,通過(guò)DataGridView.NewRowIndex 可以獲取新行的行序列號。在沒(méi)有新行的時(shí)候,NewRowIndex = -1。

[VB.NET]
If DataGridView1.CurrentRow.IsNewRow Then
     Console.WriteLine(
"當前行為新追加行。")
Else
     Console.WriteLine(
"當前行不是新追加行。")
End If

 

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
C#中DatagridView單元格動(dòng)態(tài)綁定控件
DataGridView使用技巧—獲取任意行或列的單元格文本
DataGridView獲取單元格坐標的方法
datagridview總結
DataGridView控件用法一:數據綁定
VB.NET接口范例ISpeak
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久