By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,579 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

filling columns in grid on user input event

P: 10
hi friends..i am using a grid view with one of its column as combobox.
now what i want is that when user select some option from the combobox then some of the cells only in the same row get filled automatically according to the selected option.

like if there are 4 fields in grid : emp_id , name , age , salary
and id column is of type combobox then on selecting the particular emp_id from the list , its coressponding name get displayed in the same row and then user can enter the other fields.similarlly when the emp_id get selected in the 2nd row of grid then 2nd row column "name" get filled.


how could i achieve this?
Apr 7 '10 #1

✓ answered by Frinavale

Well, if you bind a GridView to an empty data source then the GridView will not display on the screen (there's nothing to display).

So you need to create a data source that contains "empty" rows. To do this you could create a table and then add a few rows that contain "spaces" so that the table (being used as the data source) contains data but is "empty".

-Frinny

Share this Question
Share on Google+
9 Replies


Frinavale
Expert Mod 5K+
P: 9,731
A GridView is an ASP.NET control however a ComboBox is a desktop application control. What type of application are you developing? An ASP.NET application or a Windows Desktop application?

-Frinny
Apr 13 '10 #2

P: 10
@Frinavale
hi Frinavale..I am using Visual studio 2005 and developing a databse windows application in vb.net with SQL server2005 as database.

I want to bit elaborate my point.what my requirement is that my user have to create bill of items.Now some times item may be one & some time it may be more.
if there are 4 fields for the input for each item: item_no , item_name, qunatity,price
item_no is a combobox , and other are normal type in grid.
there is "master" table in database with fields :item_no , item_name
now i populate the combobox with item_no.On selection of a particular item the item_name in the grid should be filled automatically according to "master" table.Now user will enter "qty" and "price".he may repeat the process for other item if he wants to create a bill for those also.
All the data in the grid should be saved to a table with name "bill" which has 6 colmns : bill_no , bill date, item_no, item_name,qty,price.
here it is noticable that "bill_no" and "bill_date" will come from the same form but are not enterd in the grid.i mean they will be same for the whole bill form.
Apr 14 '10 #3

Frinavale
Expert Mod 5K+
P: 9,731
Quick overview:
  • You have populated your DataGridView
  • You have a ComboBox as one column in the DataGridView
  • You want to retrieve the selected item in the ComboBox when the selected index changes so that you can populate something else

I'm not sure what specifically you're having problems with so I'll guess here.
I'm assuming that you do not know how to get the selected item in the ComboBox... if that's the case then you should probably look over this article: DataGridViewComboBoxEditingControl Class. It explains how to use the ComboBox in the DataGridView.

-Frinny
Apr 14 '10 #4

P: 10
@Frinavale
hi frinvale...actually my problem is not ony limited to populating other column according to the selection of combobox in grid.What i exactly want is that there should be an empty grid every time and we can enter the info
I dont want to edit/display old records
Apr 15 '10 #5

Frinavale
Expert Mod 5K+
P: 9,731
I see.

In that case create a table with empty rows (they contain spaces or something) in it and bind to that :)


-Frinny
Apr 15 '10 #6

P: 10
@Frinavale
nice reply...bt i m nt getting u :-p .could u plz elaborate ur pint
Apr 16 '10 #7

Frinavale
Expert Mod 5K+
P: 9,731
Well, if you bind a GridView to an empty data source then the GridView will not display on the screen (there's nothing to display).

So you need to create a data source that contains "empty" rows. To do this you could create a table and then add a few rows that contain "spaces" so that the table (being used as the data source) contains data but is "empty".

-Frinny
Apr 16 '10 #8

P: 10
@Frinavale
thnx friend....actually i had alredy solved this problem..infact the solution is the same as suggested by you.i had not bound the grid to any source.as there is one combobox in the grid when i select an item from the combobx and then I click to enter something in next cell to it in the same row then system gives an runtym error " System.FormatException :Value cann't be converted to type 'System.String' "
Apr 17 '10 #9

P: 10
the value in combobx is of type tinyint(SQL)
Apr 17 '10 #10

Post your reply

Sign in to post your reply or Sign up for a free account.