نمایش نتایج 1 تا 3 از 3

نام تاپیک: راجب DataGrid در Vb.net

  1. #1

    راجب DataGrid در Vb.net

    بچه ها من می خواهم هنگامی که بر روی DataGrid فلش حرکت پایین یا بالا را می زنم نوار حرکت (رنگ آبی ) در تمامی ستون ها فعال باشد نه فقط بر روی یک ستون که بتوان از این ستون به ستون بعد رفت

  2. #2
    مهمان
    من برای این کار یک کلاس برای ستون ها ایجاد کردم و زیر برنامه زیر رو در اون قرار دادم:


    Private SelectedRow As Integer

    Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
    Try
    If (SelectedRow > -1) And (SelectedRow < source.List.Count + 1) Then
    Me.DataGridTableStyle.DataGrid.UnSelect(Select edRow)
    End If
    SelectedRow = rowNum
    Me.DataGridTableStyle.DataGrid.Select(Selected Row)
    Catch
    End Try
    End Sub


    این کد برای موس هم عمل می کنه.

  3. #3

    با سلام

    سلام دوستان این رو هم نگاه کنید

    Make the DataGrid support single select vs multiselect mode.
    You can do this by subclassing your DataGrid and overriding the
    OnMouseMove and OnMouseDown methods. I also add a new SingleSelect
    property to the DataGrid so you can toggle single selection on and off.
    Add these module level variables:
    ' Single row selection flag.

    Private mySingleSelect As Boolean = False

    ' Used to see what part of grid was clicked.
    Private myHitTestInfo As DataGrid.HitTestInfo

    Private myOldSelectedRow As Integer
    Add this property:
    Public Property SingleSelect() As Boolean
    Get
    SingleSelect = mySingleSelect
    End Get

    Set(ByVal theValue As Boolean)
    mySingleSelect = theValue
    End Set
    End Property
    Add these methods:
    Protected Overloads Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
    '
    ' Make the DataGrid support single select mode vs the default multiselect mode.
    ' Don't call the base class if left mouse down to avoid dragging selections.
    '
    On Error Resume Next

    If (e.Button <> MouseButtons.Left) Or Not mySingleSelect Then
    MyBase.OnMouseMove(e)
    End If

    End Sub


    Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
    '
    ' Make the DataGrid support single select mode vs the default multiselect mode.
    ' Handle selecting and unselecting without calling the base class if the click
    ' is on the header
    '
    On Error Resume Next

    myHitTestInfo = Me.HitTest(New Point(e.X, e.Y))

    If (myHitTestInfo.Type = Me.HitTestType.Cell) Then
    '
    ' When a grid cell is clicked prevent multi-select.
    '
    If mySingleSelect Then
    If myOldSelectedRow > -1 Then
    '
    ' Account for deleted rows.
    '
    Dim cm As CurrencyManager = _
    CType(Me.BindingContext(Me.DataSource) , CurrencyManager)

    If myOldSelectedRow > cm.Count - 1 Then
    myOldSelectedRow = cm.Count - 1
    End If

    Me.UnSelect(myOldSelectedRow)
    End If
    myOldSelectedRow = -1
    End If

    MyBase.OnMouseDown(e)
    Else
    '
    ' Prevent row resizing and multi-select.
    '
    If (myHitTestInfo.Type = Me.HitTestType.RowHeader) Then
    If myOldSelectedRow > -1 And mySingleSelect Then
    '
    ' Account for deleted rows.
    '
    Dim cm As CurrencyManager = _
    CType(Me.BindingContext(Me.DataSource) , CurrencyManager)

    If myOldSelectedRow > cm.Count - 1 Then
    myOldSelectedRow = cm.Count - 1
    End If

    Me.UnSelect(myOldSelectedRow)
    End If

    If ((Control.ModifierKeys And Keys.Shift) = 0) Then
    MyBase.OnMouseDown(e)
    Else
    If mySingleSelect Then
    Me.CurrentCell = New DataGridCell(myHitTestInfo.Row, myHitTestInfo.Column)
    End If
    End If

    Me.Select(myHitTestInfo.Row)
    myOldSelectedRow = myHitTestInfo.Row
    End If
    End If
    End Sub


    For the C#‎ programmer, add these fields:

    // Single row selection flag.
    private bool mySingleSelect = false;

    // Used to see what part of grid was clicked.
    private DataGrid.HitTestInfo myHitTestInfo;

    private int myOldSelectedRow;
    Add this property:
    public bool SingleSelect
    {
    get
    {
    return mySingleSelect;
    }
    set
    {
    mySingleSelect = value;
    }
    }
    Add these methods:
    protected override void OnMouseMove(MouseEventArgs e)
    {
    //
    // Make the DataGrid support single select mode vs the default multiselect mode.
    // Don't call the base class if left mouse down to avoid dragging selections.
    //
    if ((e.Button != MouseButtons.Left) | (mySingleSelect == false))
    {
    base.OnMouseMove(e);
    }
    }


    protected override void OnMouseDown(MouseEventArgs e)
    {
    //
    // Make the DataGrid support single select mode vs the default multiselect mode.
    // Handle selecting and unselecting without calling the base class if the click
    // is on the header
    //

    myHitTestInfo = this.HitTest(new Point(e.X, e.Y));

    if (myHitTestInfo.Type == HitTestType.Cell)
    {
    //
    // When a grid cell is clicked prevent multi-select.
    //
    if (mySingleSelect)
    {
    if (myOldSelectedRow > -1)
    {
    //
    // Account for deleted rows.
    //
    CurrencyManager cm = (CurrencyManager)this.BindingContext[t his.DataSource];

    if (myOldSelectedRow > cm.Count - 1
    myOldSelectedRow = cm.Count - 1;

    this.UnSelect(myOldSelectedRow);
    }
    myOldSelectedRow = -1;
    }
    base.OnMouseDown(e);
    }
    else
    {
    //
    // Prevent row resizing and multi-select.
    //
    if (myHitTestInfo.Type == HitTestType.RowHeader)
    {
    if ((myOldSelectedRow > -1) & (mySingleSelect))
    {
    //
    // Account for deleted rows.
    //
    CurrencyManager cm = (CurrencyManager)this.BindingContext[t his.DataSource];

    if (myOldSelectedRow > cm.Count - 1)
    myOldSelectedRow = cm.Count - 1;

    this.UnSelect(myOldSelectedRow);
    }

    if ((Control.ModifierKeys & Keys.Shift) == 0)
    base.OnMouseDown(e);
    else
    {
    if (mySingleSelect)
    this.CurrentCell = new DataGridCell(myHitTestInfo.Row, myHitTestInfo.Column);
    }

    this.Select(myHitTestInfo.Row);
    myOldSelectedRow = myHitTestInfo.Row;
    }
    } //else
    } // OnMouseDown


    با تشکر
    شهریار

تاپیک های مشابه

  1. کنترل کلیدها در DataGrid
    نوشته شده توسط once4ever در بخش C#‎‎
    پاسخ: 10
    آخرین پست: چهارشنبه 26 آبان 1389, 23:31 عصر
  2. نمایش یک رکورد جدول به صورت دو سطر در datagrid
    نوشته شده توسط zahracomputer در بخش ASP.NET Web Forms
    پاسخ: 11
    آخرین پست: چهارشنبه 12 مهر 1385, 20:22 عصر
  3. دستور If در DataGrid
    نوشته شده توسط shahramasp در بخش ASP.NET Web Forms
    پاسخ: 2
    آخرین پست: چهارشنبه 14 تیر 1385, 21:12 عصر
  4. مشکل در کار با datagrid
    نوشته شده توسط radan63 در بخش ASP.NET Web Forms
    پاسخ: 7
    آخرین پست: سه شنبه 29 فروردین 1385, 09:27 صبح
  5. سه رقم سه رقم جداکردن در datagrid
    نوشته شده توسط Beyondsoft در بخش VB.NET
    پاسخ: 8
    آخرین پست: پنج شنبه 24 فروردین 1385, 18:53 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •