PDA

View Full Version : datagridview



soheil3242
جمعه 11 مرداد 1387, 19:11 عصر
سلام
چه طور ميتونم يه datagridview داشته باشم كه به يه منبع اطلاعات bind شده باشه كه بتونم از اون براي ويرايش اطلاعات استفاده كنم و ستونهاي اون مثلا شامل combox و datetimepicker يا حتي يه تقويم فارسي باشه ؟ آيا كامپوننتي براي اين نوع datagridview سراغ داريد ؟ ممنون .

reza6384
شنبه 12 مرداد 1387, 17:19 عصر
امکانات DataGridView ای که Net. داره کمه. بعضی از این کارها که گفتین رو می تونین باهاش انجام بدین که قیلا تو سایت بحث شده، مثل اینکه یک سلول اون ComboBox باشه. اگر DataGrid با امکانات زیاد می خواین یه سر به www.janus.com (http://www.janus.com) بزنید. امکاناتش فوق العاده هست و نیازهاتون رو کاملا براورده می کنه.

Dariuosh
شنبه 12 مرداد 1387, 23:40 عصر
امکانات DataGridView ای که Net. داره کمه.
يکي از حسناش اينه که با يه ذره حوصله هر چيزي بخواي ميتوني بهش اضافه کني


NumericUpDownColumn (http://msdn.microsoft.com/en-us/library/aa730881(VS.80).aspx)
RadioButtonColumn (http://msdn.microsoft.com/en-us/library/aa730882(VS.80).aspx)
BarGraphColumn (http://www.devx.com/codemag/Article/35186/0/page/1)

Dariuosh
یک شنبه 13 مرداد 1387, 00:22 صبح
اينم برا مثال بيشتر
رو فرمتون يه DataGridView بندازين



Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Private Sub form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim dt As New DataTable()
dt.Columns.Add("col1")
dt.Columns.Add("col2")
For j As Integer = 0 To 19
dt.Rows.Add("col1" + j.ToString(), "col2" + j.ToString())
Next
Me.DataGridView1.DataSource = dt
Me.DataGridView1.Columns(0).Width = 150
Me.txbtnControl = New TextAndButtonControl()
Me.txbtnControl.Visible = False
Me.DataGridView1.Controls.Add(Me.txbtnControl)
AddHandler Me.DataGridView1.CellPainting, AddressOf dataGridView1_CellPainting
AddHandler Me.DataGridView1.CellBeginEdit, AddressOf dataGridView1_CellBeginEdit
AddHandler Me.DataGridView1.CellEndEdit, AddressOf dataGridView1_CellEndEdit
AddHandler Me.DataGridView1.Scroll, AddressOf dataGridView1_Scroll
End Sub
Private txbtnControl As TextAndButtonControl
Private Sub dataGridView1_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs)
If e.ColumnIndex = 0 AndAlso e.RowIndex > -1 AndAlso e.RowIndex <> Me.DataGridView1.NewRowIndex Then
Dim textRect As Rectangle = e.CellBounds
textRect.Width -= e.CellBounds.Width / 3
Dim btnRect As Rectangle = e.CellBounds
btnRect.X += textRect.Width
btnRect.Width = e.CellBounds.Width / 3
e.Paint(textRect, DataGridViewPaintParts.All)
ControlPaint.DrawButton(e.Graphics, btnRect, ButtonState.Normal)
Dim formater As New StringFormat()
formater.Alignment = StringAlignment.Center
e.Graphics.DrawString("click", e.CellStyle.Font, New SolidBrush(e.CellStyle.ForeColor), btnRect, formater)
e.Handled = True
End If
End Sub
Private Sub dataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As DataGridViewCellCancelEventArgs)
If e.ColumnIndex = 0 AndAlso e.RowIndex > -1 AndAlso e.RowIndex <> Me.DataGridView1.NewRowIndex Then
Dim rect As Rectangle = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnI ndex, e.RowIndex, True)
Me.txbtnControl.Location = rect.Location
Me.txbtnControl.Size = rect.Size
Me.txbtnControl.Text = Me.DataGridView1.CurrentCell.Value.ToString()
Me.txbtnControl.ButtonText = "click"
Me.txbtnControl.renderControl()
Me.txbtnControl.Visible = True
End If
End Sub
Private Sub dataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
If e.ColumnIndex = 0 AndAlso e.RowIndex > -1 AndAlso e.RowIndex <> Me.DataGridView1.NewRowIndex Then
Me.DataGridView1.CurrentCell.Value = Me.txbtnControl.Text
Me.txbtnControl.Visible = False
End If
End Sub
Private Sub dataGridView1_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs)
If Me.txbtnControl.Visible = True Then
Dim r As Rectangle = Me.DataGridView1.GetCellDisplayRectangle(Me.DataGr idView1.CurrentCell.ColumnIndex, Me.DataGridView1.CurrentCell.RowIndex, True)
Me.txbtnControl.Location = r.Location
Me.txbtnControl.Size = r.Size
End If
End Sub
End Class


اينم يه UserControl الکي يه TextBox با Button
زيره همين کد بالايي يه کپيش کنيد


Class TextAndButtonControl
Inherits UserControl
Private textbox1 As TextBox
Private button1 As Button
Public Sub New()
Me.textbox1 = New TextBox()
Me.Controls.Add(Me.textbox1)
Me.button1 = New Button()
Me.Controls.Add(Me.button1)
Me.renderControl()
AddHandler Me.button1.Click, AddressOf button1_Click
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("Click! The value is:" + Me.Text)
End Sub
Public Overrides Property Text() As String
Get
Return Me.textbox1.Text
End Get
Set(ByVal value As String)
Me.textbox1.Text = value
End Set
End Property
Public Property ButtonText() As String
Get
Return Me.button1.Text
End Get
Set(ByVal value As String)
Me.button1.Text = value
End Set
End Property
Public Sub renderControl()
Me.textbox1.Location = New Point(0, 0)
Me.textbox1.Width = 2 * Me.Width / 3
Me.textbox1.Height = Me.Height
Me.button1.Location = New Point(2 * Me.Width / 3, 0)
Me.button1.Width = Me.Width / 3
Me.button1.Height = Me.Height
End Sub
End Class

msh_gold
یک شنبه 13 مرداد 1387, 05:33 صبح
سلام ببخشيد منم يه مشكل با data gridview دارم كه اگه ميشه كسي كمكم كنه من ميخوام در حالت اجرا وقتي كه اطلاعاتم رو در بانك ثبت مي كنم در پايين datagrid ركوردم ثبت بشه وكاربر بتونه ببينه چه رو ثبت كرده.با تشكر فراوان

soheil3242
یک شنبه 13 مرداد 1387, 08:44 صبح
سلام آقاي رضا6384 سايت janus.com متاسفانه فيلتر شده .

amirzazadeh
یک شنبه 13 مرداد 1387, 08:54 صبح
سلام ببخشيد منم يه مشكل با data gridview دارم كه اگه ميشه كسي كمكم كنه من ميخوام در حالت اجرا وقتي كه اطلاعاتم رو در بانك ثبت مي كنم در پايين datagrid ركوردم ثبت بشه وكاربر بتونه ببينه چه رو ثبت كرده.با تشكر فراوان
اگر من درست متوجه شده باشم مشكل شما با رفرش كردن ديتاگريد حل ميشه.

me.refresh

reza6384
یک شنبه 13 مرداد 1387, 20:55 عصر
سلام آقاي رضا6384 سايت janus.com متاسفانه فيلتر شده .

با گوگل U88.exe یا U89.exe رو جستجو و دانلود کنید. مشکلتون حل می شه.