Dear Freinds
I want to help regarding datagrid. i want that when i select any value from combobox of datagrid( value in combobox come from databse) the textbox of same datgrid show the value of slecete combo box no from same databse

simply

i select a item no form database in combo box of datagrid now i want textbox of datagrid show the item name related to the particular of a particular item no

Recommended Answers

All 9 Replies

your words are not well explanatory. State clearly what you want

yr in simple words

i want that in datagrid view i want to select only product number(datagrid combo box) and then product name(datagrid textbox) come automatically in datagrid which match to the product number. product number and product name come from database whaere i save this numbers and name from add new product form

i have combobox column and on selection of the combobox data i want the text field column of the datagrid view to get the text based on the selection of the data in the combobox column

the text in the textbox will come from the database based on data selected in combobox

i have done the bit its not working it is giving "Object reference not set to an instance of an object".

plz help me regarding this problem

Dim counter, abc As Integer
For abc = 0 To DataGridView1.Rows.Count - 1
Dim mydataa = From d In voucher.Vend_masts Select d _
Where d.address = Val(DataGridView1.Rows(abc).Cells(0))
DataGridView1.Rows(abc).Cells(1).Value = mydataa.FirstOrDefault.contact_no

this is my coding
now please tell me where i am wrong

Can you show your table structure ???
like:

Field Datatype
vr_no int
. .
. .
. .
etc...

because my guess is that you are getting "Nothing" in "mydataa" and to check this, first i need to know the structure of table to help you.

1 bill_no int 4 1
0 s_no varchar 6 1
0 item_name varchar 20 1
0 qty varchar 6 1
0 price float 8 1
0 discount float 8 1
0 d_price float 8 1
0 perqty float 8 1
0 total float 8 1
0 party_name varchar 20 1

If I understood correctly that you are willing to create two columns in DataGridView and in first column you have a ComboBox, from the seletcion of ComboBox item, you want to populate the 2nd column(TextBox Column) of DatagridView ??? Am I right ???

Hi! I came up with a possible code:

I created a table "tblA" having column "ID as Number" and "Text as String".
"ID" in datagridview is ComboBoxColumn and "Text" in datagridview is TextBoxColumn.

USAGE:
Select a value in ComboBoxColumn and "PRESS Enter".

I didn't find any suitable event to raise when a ComboBoxColumn value is updated. so I put it in Cell_EndEdit which "nearly" works according to your need.

YOUR TASK IS TO FIND THAT PARTICULAR EVENT and call method CallUpdate() within that event

Private cmbo As New DataGridViewComboBoxColumn()
Private tbCol As New DataGridViewTextBoxColumn()
Private Sub Form1_Load(sender As Object, e As EventArgs)
	dataGridView1.AutoGenerateColumns = False
	Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb")
	Dim cmd As New OleDbCommand("Select * from tblA", con)
	con.Open()
	Dim rdr As OleDbDataReader = cmd.ExecuteReader()
	Dim list As IList(Of String) = New List(Of String)()
	While rdr.Read()
		list.Add(rdr("ID").ToString())
	End While
	con.Close()
	cmbo.DataSource = list
	dataGridView1.Columns.Add(cmbo)
	dataGridView1.Rows.Add(list.Count())
	dataGridView1.Columns.Add(tbCol)
End Sub

Private Sub dataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs)
	CallUpdate()
End Sub

Public Sub CallUpdate()
	Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Shahan\Documents\Visual Studio 2010\Projects\TestDB\TestDB\test.mdb")
	con.Open()
	For Each row As DataGridViewRow In dataGridView1.Rows
		Dim cmd As New OleDbCommand("Select Text from tblA where ID=" & Convert.ToInt32(row.Cells(0).Value), con)
		Dim val As Object = cmd.ExecuteScalar()
		row.Cells(1).Value = val
	Next
	con.Close()
End Sub
commented: Helpful :) +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.