Combobox and Grid on Windows Form

J

Jeremy

I have a combo box and a grid on the windows form. I have the grid
populated with data from a query with on simple join to show the user
friendly description of the ID that is in the table. When I click on
one row of the grid, I will show the value in the combo box. When the
user changes the value of the combo box, I want to have that value
reflected in the appropriate column in the grid. When the user is done
making the changes, a button will be pressed to commit all of the
changes to the database. Just so you know, in grid editing is out of
the question for this project. The standard is to have a seperate combo
box to do all of the editing. What is the best way of going about this?
I currently have it set up so that the grid is bound to a dataset
containing all of the information with the join query. I looked into
having a dataset with two datatables with a datarelation, but then the
grid will not display the way I want it to. I dont see an easy way to
display the unique values in the combo box without binding it to its
own dataset, then manually finding the record in the other dataset and
updating the appropriate column. I dont mind doing that, but I want to
know if there is a better method.

thanks!
 
J

Jeremy

Hi Cor,
Thanks for the quick response. This code sample highlights the problem
I am dealing with. There is a problem, though. Lets say that table1
contains just foreign key information. If I change your code to read
this:
dtName.LoadDataRow(New Object() {"0", "Herfried K. Wagner",
"0"}, True)
dtName.LoadDataRow(New Object() {"1", "Cor Ligthert", "2"},
True)
dtName.LoadDataRow(New Object() {"2", "Armin Zingler", "1"},
True)
dtName.LoadDataRow(New Object() {"3", "Ken Tucker", "4"}, True)
dtName.LoadDataRow(New Object() {"5", "Terry Burns", "5"},
True)

Where your first table has just the key, how do I then display in my
grid the user-friendly description of the number. The number is
meaningless to the end user. How do I do this without a join?
 
J

Jeremy

The other problem I have which this does not address is that I am only
updating one table in the database, but am displaying data from 2. So I
need to choose a value in the combo box, then update the hidden field
with the correct id to write to the database while showing the correct
user-friendly value. I used to do this in VB6 all the time, but I am
trying to do this "the .NET way" I am wondering if I just need to write
all the plumbing code that I had to before. I was hoping there was a
way that ADO.NET handled this kind of situation.
 
C

Cor Ligthert

Jeremy,
Where your first table has just the key, how do I then display in my
grid the user-friendly description of the number. The number is
meaningless to the end user. How do I do this without a join?
Do you know what was one of the greatest changes with the old sample, beside
a what clumsy adding of rows in the old: I removed the datagridstyles,
because therefore the sample looked more on a style sample than a sample for
this problem. Therefore do I advice you to use those styles for your problem
as you describe it now.

http://msdn.microsoft.com/library/d...mWindowsFormsDataGridTableStyleClassTopic.asp

By the way. I answered 5 minutes ago as well a question from Jeremy in the
newsgroup VBNet. I expected it was the same Jeremy, now I saw from the mail
address that it are two different persons. (My assumption was direct that
you were using VBNet)

I hope this helps,

Cor
 
J

Jeremy

It looks like the grid styles are not going to help me since i am using
an Infragistics grid to do this. they have completely changed the model
for alot of stuff. There doesn't seem to be an easy way to do this.

On a somewhat related topic, I am reading the ADO.NET book by David
Sceppa published by Microsoft. They seem to be recommending moving away
from joined queries. If I can't get a VERY simple example of grid to
combo mapping working in this new scheme, I will have no choice but to
force some kind of ugly solution to this problem. Especially once I
start coding complex data entry forms that could have 3 or 4 related
tables. Any thoughts on this? Surely I can't be the only one trying to
do this!?!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top