PDA

View Full Version : نمایش اطلاعات دیتا گرید در داخل تکس باکس با استفاده از binding source



sinaexample
پنج شنبه 13 تیر 1392, 18:23 عصر
با سلام دوستان اگه تو این موضوع کمکم کنید ممنون میشم
میخوام با کلیک روی هر سطر که در دیتا گرید ویو نمایش داده میشه اطلاعات داخل فیلد مربوطه درج بشه که بعدا بشه تغییر داد. حالا من با تغییرش مشکلی ندارم فقط با نشون دادن مشکل دارم
مثلن تو این شکل میخوام رو هر کدوم از اعضا که کلیک بشه مثلن تو قسمت کد کدش رو بنویسه تو نام نامش رو و...
http://www.8pic.ir/images/67199411825825517234.jpg (http://www.8pic.ir/)
کدی که براش نوشتم هم اینه ولی کار نمیکنه:



Imports System.IO

Imports BAL
Imports Business_Entity
Public Class FrmEditMember
Dim obj_member As memberBAL
Dim Member As New EntMember
Dim BS_member As New BindingSource




Private Sub FrmEditMember_Load(sender As Object, e As EventArgs) Handles MyBase.Load

obj_member = New memberBAL(My.Settings("conasli"))
BS_member.DataSource = obj_member.fill
DataGridView1.DataSource = BS_member
btn_browse.Enabled = False
btn_delete.Enabled = False
btn_update.Enabled = False
End Sub

Private Sub DataGridView1_Click(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.Click
ErrorProvider1.Clear()
txtsearch.Clear()
btn_browse.Enabled = True
btn_delete.Enabled = True
btn_update.Enabled = True
Dim indexrow As Integer = BS_member.Position
Try
txtcode.Text = DataGridView1.Rows(indexrow).Cells(0).Value
txtfname.Text = DataGridView1.Rows(indexrow).Cells(1).Value
txtlname.Text = DataGridView1.Rows(indexrow).Cells(2).Value
txtsh.Text = DataGridView1.Rows(indexrow).Cells(3).Value
txtfather.Text = DataGridView1.Rows(indexrow).Cells(4).Value
cmbgride.Text = DataGridView1.Rows(indexrow).Cells(5).Value
txttell.Text = DataGridView1.Rows(indexrow).Cells(6).Value
Dim buffer() As Byte = CType(DataGridView1.Rows(indexrow).Cells(7).Value, Byte())
Dim str As New IO.MemoryStream(buffer)
picmember.Image = Image.FromStream(str)
Catch ex As Exception
MsgBox("error")
End Try
End Sub
End Class







اگه کسی میدونه مشکل کجاست لطفا کمکم کنه
بعد از اجرا این اخطار رو میده:
Unable to cast object of type 'System.Windows.Forms.MouseEventArgs' to type 'System.Windows.Forms.DataGridViewCellEventArgs'.

DavoodJafary
یک شنبه 18 خرداد 1393, 11:34 صبح
با سلام دوستان اگه تو این موضوع کمکم کنید ممنون میشم
میخوام با کلیک روی هر سطر که در دیتا گرید ویو نمایش داده میشه اطلاعات داخل فیلد مربوطه درج بشه که بعدا بشه تغییر داد. حالا من با تغییرش مشکلی ندارم فقط با نشون دادن مشکل دارم
مثلن تو این شکل میخوام رو هر کدوم از اعضا که کلیک بشه مثلن تو قسمت کد کدش رو بنویسه تو نام نامش رو و...
http://www.8pic.ir/images/67199411825825517234.jpg (http://www.8pic.ir/)
کدی که براش نوشتم هم اینه ولی کار نمیکنه:



Imports System.IO

Imports BAL
Imports Business_Entity
Public Class FrmEditMember
Dim obj_member As memberBAL
Dim Member As New EntMember
Dim BS_member As New BindingSource




Private Sub FrmEditMember_Load(sender As Object, e As EventArgs) Handles MyBase.Load

obj_member = New memberBAL(My.Settings("conasli"))
BS_member.DataSource = obj_member.fill
DataGridView1.DataSource = BS_member
btn_browse.Enabled = False
btn_delete.Enabled = False
btn_update.Enabled = False
End Sub

Private Sub DataGridView1_Click(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.Click
ErrorProvider1.Clear()
txtsearch.Clear()
btn_browse.Enabled = True
btn_delete.Enabled = True
btn_update.Enabled = True
Dim indexrow As Integer = BS_member.Position
Try
txtcode.Text = DataGridView1.Rows(indexrow).Cells(0).Value
txtfname.Text = DataGridView1.Rows(indexrow).Cells(1).Value
txtlname.Text = DataGridView1.Rows(indexrow).Cells(2).Value
txtsh.Text = DataGridView1.Rows(indexrow).Cells(3).Value
txtfather.Text = DataGridView1.Rows(indexrow).Cells(4).Value
cmbgride.Text = DataGridView1.Rows(indexrow).Cells(5).Value
txttell.Text = DataGridView1.Rows(indexrow).Cells(6).Value
Dim buffer() As Byte = CType(DataGridView1.Rows(indexrow).Cells(7).Value, Byte())
Dim str As New IO.MemoryStream(buffer)
picmember.Image = Image.FromStream(str)
Catch ex As Exception
MsgBox("error")
End Try
End Sub
End Class







اگه کسی میدونه مشکل کجاست لطفا کمکم کنه
بعد از اجرا این اخطار رو میده:
Unable to cast object of type 'System.Windows.Forms.MouseEventArgs' to type 'System.Windows.Forms.DataGridViewCellEventArgs'.



با سلام

;()txtGroupName.Text = grwGroup.CurrentRow.Cells["groupName"].Value.ToString
در اینجا بجای groupName نام فیلد داخل گرید ویو را به textbox اختصاص می دهیم.

این رو هم بگم باید در رویداد
grwGroup_RowHeaderMouseDoubleClick
کد را بنویسید.