Unbound Columns in DataGridview

Reaction

Member
Joined
Apr 29, 2007
Messages
13
Programming Experience
1-3
1) I need to have the values of some unbound columns in my datagridview automatically calculated and updated when values in bound columns are changed. How do I handle this please?

2) I have a DataGridViewComboBox that is populated on form load but I would also like the selected value of my DataGridviewComboBox set at Form load to the value of the Shopping Cart's value. How do I handle this best please?

3) I also want to have the value in one of my unbound column changed as soon as user selects a new value in my DataGridviewComboBox

Reaction
 
Can you post your code with some indentation? You may have to switch the editor to BASIC mode using the
switchmode.gif
button
 
cjard,

I followed along with your video clip which was extremely helpful in getting me to this point. However, I cannot seem to get the comboboxes to "drop down".

Real quick, in a nut shell here is what i'm trying to do. I have two tables:

Table 1 contains various PC client data which I was able to compare to your "People" table in your vid.

Table 2 contains all the ip and mac address's of those PCs. (compare to your "Lookup" table) I store this in a separate table since it is possible for PC clients to have more than one IP/MAC.

I will use my IP column for my question, but its pretty much the same setup with the mac column.

The data properties on my ip comboboxcolumn is as follows:

DataPropertyName = id (primary key on table 1)
DataSource = NicsBindingSource (sql table)
DisplayMember = ip (ip column)
ValueMember = client_id (references the primary key on table 1)

It's getting the correct information because the IP/MACs it's coming up with are correct. But I know for a fact on some of the PC clients I should have multiple IPs/MACs, but if I click the drop down, i don't get anything.

If you need more info. let me know, but the main purpose of my application is to provide a table full of PC data which i will be able to interact with via WMI when the application is finished. I would like to use a DGV as the method/interface for that data. Thanks for any help and for the vid. clip! :D
 
If youre not editing anything then you should not set the DataPropertyName or the ValueMember

I presume you want a row that has the PC details like name, owner etc and then a column that has a combo showing all the IPs

You need in your dataset:

PCTable
--------
PCName
PCSpec

IPTable
-------
PCName
IPAddress


A DataRelation PCTable_IPTable (parent_child) linked on PCName

On your form:
A DataGridView bound to PCTableBindingSource bound to MyDataSet.PCTable
A PCIPChildrenBindingSource bound to PCTable.PCTable_IPTableDataRelation
A DataGridViewComboBoxColumn bound to PCIPChildrenBindingSource and having its DisplayMember set to "IPAddress"

You see, the whole point is that the datarelation performs filtering. You fill the child datatable with ALL records available for all pcs and all ips. Then when you alter the Current of the Parent bindingsource it affects what is available in the list of the childbindingsource. You select the MY_HOME_PC row in the grid, parent is the MY_HOME_PC row, children are filtered to only MY_HOME_PC elements. Dropping down the combo shows all IP addreses assigned to that pc
 
Ok,

First off thanks again for your help. You are the bomb!

What you described made perfect sense to me and is exactly what i was after. I went through your list of changes and the only one i modified slightly was instead of using the pc name for the relation i used my primary key which is just an integer. So my relation looks something like:

VB.NET:
PC table IP table
PK_id---+ id
name    +--clientID
etc..      ip
            etc..
Other than that, i made all the other appropriate adjustments, but i'm not getting any results in my comboboxes. I'll fiddle around with it some more, but if you have any additional input that would be great! Thanks again! :)
 
Last edited:
cjard rocks

I got it ... i'm not sure what i did wrong the first round, but i just scrapped the entire project and re-wrote it and it worked perfectly!

Again, thanks. You are the man! :D
 
Put a button on the form with a useless statement in like Dim i as Integer = 0
Put a breakpoint on the useless statement
Highlight a row in the grid
Press the button
Into the immediate window write:
MyChildBindingSource.Count

What is the value?
If it is 0 do:

MyChildDatatable.Count

If it is 0, you didnt fill any children into your datatable
If it is not 0, check that parent rows actually have children by writing this into the Immediate window:

ParentDatatable(0).GetChildRows()



Note when I say Immediate window, I mean Immediate window, not COmmand window
 
Back
Top