|
I am using a DataGridView to display (and sometimes update) data stored in an Access Table. The Access Table includes a cell that uses a "Lookup" so that the cell values that are displayed are from another table, but what is stored in the cell is simply an integer. In the DataGridView, the integer is displayed. Is there some way that I can connect a ComboBox to the cell in the DataGridView so that the integer becomes an index to the ComboBox list?
Rich Feldman
|
|
|
|
|
You would normally create your own DataGridView columns, not relying on the auto-generated columns. Basically, you're getting two tables from the database into a DataSet. The first is the data your showing in the DGV. The second supplies the values you want to show in the ComboBox column. You can then create a ComboBox column using something like:
Private Sub SetupDataGridView()
DGV1.Columns.Clear()
' Table1 is going to have our data in it.
' Table2 is supplying what shows up in the ComboBox's.
Dim newCol As New DataGridViewComboBoxColumn
With newCol
.HeaderText = "headertext"
.DataSource = table2
.DataPropertyName = "columnNameInTable1HoldingForeignKey"
.ValueMember = "columnNameInTable2HoldingPrimaryKey"
.DisplayMember = "columnNameInTable2HoldingComboBoxDescriptions"
.Width = whatever...
End With
DGV1.Colums.Add(newCol)
Table 1 should have to foreign keys into Table 2, like:
IDKey FKeyIn2 data1 data2
1 1 "Hi!" "There!"
2 4 "More" "Data"
Table 2 should have the text descriptions you'll see in the CombBox like this:
IDKey Description
1 "Some text..."
2 "Some more text..."
3 "Another item"
4 "Who cares"
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thank-you for your response. I have managed to create the column so that the display is proper, but am having trouble giving the initial values to the column. Using the notation from your example, my difficulty is in specifying that the initial values come from Table1. Again, following your code, I have done the following (assuming that the column names are equal to the column headings).
Private Sub SetupDataGridView()
DGV1.Columns.Clear()
' Table1 is going to have our data in it.
' Table2 is supplying what shows up in the ComboBox's.
Dim newCol As New DataGridViewComboBoxColumn
With newCol
.DataSource = table2
.DataPropertyName = "FKeyIn2" 'HOW IS THIS RELATED BACK TO TABLE1 ???
.ValueMember = "IDKey"
.DisplayMember = "Description"
End With
DGV1.Colums.Add(newCol)
What I don't understand is how does newCol know that Table1 contains the required index values for the ComboBox? The column of Table1 is specified but not the table iteself. In other words, the statement
.DataPropertyName = "FKeyIn2"
is unrelated to Table1 with respect to the data contained within newCol. Any further suggestions?
Rich Feldman
|
|
|
|
|
FNKey in Table1 must match the IDKey in Table2.
The values in the FNKey column in Table1 are used to look up the description matching that value in Table2.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
i have problem for clear the picture box in visual studio 2005 when click on 'new' button
|
|
|
|
|
If not isnothing(picture1.image) then
picture1.image.dispose()
picture1.image = nothing
end if
|
|
|
|
|
|
I have a table with a primary key and using the code below works fine
Dim dsChanges = ds.GetChanges
If IsNothing(dsChanges) Then
Return False
Else
Dim cmdCommandBuilder As System.Data.Common.DbCommandBuilder = Factory.CreateCommandBuilder
cmdCommandBuilder.DataAdapter = adAdapter
adAdapter.Update(ds, kvpQT.Key)
Return True
End If
but this code doesnot work when there is no primary key in the table.
If i need to update a table which only has a foreign key then i need to use the query and this method does not work.
How can i update the table through dataset without table having the primary key.
|
|
|
|
|
In order to use a DataAdapter, all of your tables in the DataSet MUST have primary keys. A DataAdapter cannot work with tables without PKeys.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I have to read the .dwg files from our application & fetch the data like no & thickness of wall etc
but i have no idea about autocad ...
plzzzzzzzz healp me
|
|
|
|
|
Google is your friend. I'm sure the autocad file format has been documented somewhere.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
sorry gurus
But i cannot find any forum dedicated to VB.
I have a some maskEdbox on my form.
mask property of each maskEdBox is set to "##/##/####".
problem is that whenever i click on it date and month are ger exchanged.
on got_focus and on key_press some codes r ther like
Private Sub mskProjCompExpDt_GotFocus()
SendKeys "{home}+{end}"
End Sub
Private Sub mskProjCompExpDt_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then SendKeys "{tab}"
End Sub
actually i dont have any idea about this control
suggest me
its very urgent
|
|
|
|
|
MissionSuccess wrote: But i cannot find any forum dedicated to VB.
ROTFL. You're in it.
MissionSuccess wrote: problem is that whenever i click on it date and month are ger exchanged.
In what direction are they changing ? What is your locale set up for in this regard ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
actually i m not understanding
y they r changing some times and sometimes they r not changing
wht could be the reason behind it.
|
|
|
|
|
I really can't help you if you won't answer my questions.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I am not getting what u want...,
tell me ur doubt clearly..,
I will try to help.....,
Magi
|
|
|
|
|
hi all
i want to find IP address & Name of all the PC connected in LAN
i want to list all the name & IP of Computers in Datagrid
plz help me
SP
--
Bugs can neither be created nor be removed from software by a developer. They can only be converted from one form to another. The total number of bugs in the software always remain constant.
|
|
|
|
|
You'll have to ping every IP address in the range of IP's you want to see if a machine responds. If something does responds, you then do a DNS lookup to resolve the address to a name.
There are, of course, a couple of problems. The first is that if the target machine has a firewall setup to ignore and not responds to ICMP requests, the ping will fail even though there is a machine there. There is no workaround for this. The second is if the machine is turned off or in the middle of rebooting. The same ping failure will occur and you'll miss a machine that's on your network.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Please give full example.
Thanks
................
|
|
|
|
|
Then what fun would it be for you to write it?
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
In vb.net
i want to get the information about hard disk partition.
for each partition whats the access level(eg c:, E: , D: )
whats the security level (e: is read only or write denied).
i need to change the write allowed access to write denied.
any idea post me
|
|
|
|
|
Imports System.Io class
and get all answers for ur questions.
|
|
|
|
|
hi all..
i m from ahmedabad,india.
i want the info. abt good coching institute(in ahmedabad) for MCPD.
i want your advice abt that exam also....
plz help........thks in advs....
Imagine the I.T
|
|
|
|
|
1 - exams are a waste of time
2 - the fact that people look for coaching specific to the exam, is the reason they have no value whatsoever.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: exams are a waste of time
Some companies will look more favourably on those that have passed the exam. Therefore it can be advantageous when seeking employment.
|
|
|
|