ورود

View Full Version : سوال: گذاشتن ستون ردیف در دیتا گرید



f_arab
دوشنبه 24 آبان 1389, 11:16 صبح
سلام دوستان عزیز
من تو دیتا گرید یک ستون اضافه کردم که ردیف رو نشون بده و با اضافه کردن بانک به دیتاگرید به تعداد رکوردهای جدول، سطرهای اونم زیاد بشه، البته شماره گذاری شده و وقتی هم که یک رکورد از جدول رو حذف می کنم ترتیب ردیف به هم نخوره به عنوان مثال اگه رکورد دوم رو حذف کردم ردیف از1 به 3 نره
اگه ستون ردیف رو توب جدولم اضافه کنم با حذف رکورد دقیقا همون اتفاقی میفته که عرض کردم
به نظر شما من باید چه کار کنم؟
لطفا منو راهنمایی کنید
متشکرم:لبخندساده:

singel
دوشنبه 24 آبان 1389, 13:03 عصر
سلام دوست عزیز ببین این بکارت میاد




Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEve ntArgs) Handles DataGridView1.CellFormatting
DataGridView1.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
End Sub

ali_najari
دوشنبه 24 آبان 1389, 14:40 عصر
دويت عزيز اگر اين كار رو توي رويداد CellPainting انجام بديد خيلي بهتر هستش



Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEvent Args) Handles DataGridView1.CellPainting
If e.RowIndex = 0 AndAlso e.ColumnIndex = 0 Then
DataGridView1.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
End If
End Sub

f_arab
دوشنبه 24 آبان 1389, 15:27 عصر
دويت عزيز اگر اين كار رو توي رويداد CellPainting انجام بديد خيلي بهتر هستش



PrivateSub DataGridView1_CellPainting(ByVal sender AsObject, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEvent Args) Handles DataGridView1.CellPainting
If e.RowIndex = 0 AndAlso e.ColumnIndex = 0 Then
DataGridView1.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
EndIf
EndSub

این کارو انجام دادم ولی فقط به سطر اول شماره یک میده و بقیه سطرها خالی هستند

Mani_rf
دوشنبه 24 آبان 1389, 15:38 عصر
خود SQL یک تابع با نام ROW_NUMBER داره که میتونی موقع فراخوانی به دیتا ورودی شماره سطر بدی.


اطلاعات بیشتر را اینجا بخوانید. (http://msdn.microsoft.com/en-us/library/ms186734.aspx)

kebriya
سه شنبه 25 آبان 1389, 10:13 صبح
در رویداد RowPostPaint گرید کد زیر رو بنویس. یه نمونه هم گذاشتم.



Using b As SolidBrush = New SolidBrush(DataGridView1.RowHeadersDefaultCellStyl e.ForeColor)
e.Graphics.DrawString("", DataGridView1.DefaultCellStyle.Font, b, DataGridView1.Size.Width - 40, 6)
e.Graphics.DrawString(e.RowIndex + 1, DataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + DataGridView1.Size.Width - 40, e.RowBounds.Location.Y)
End Using

ali_najari
سه شنبه 25 آبان 1389, 16:58 عصر
دوستان من كدم رو اصلاح ميكنم چون حق با شماست بايد مينوشتم بزرگتر و برابر صفر


PrivateSub DataGridView1_CellPainting(ByVal sender AsObject, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEvent Args) Handles DataGridView1.CellPainting
If e.RowIndex >= 0 AndAlso e.ColumnIndex = 0 Then
DataGridView1.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
EndIf
EndSub