-
October 11th, 2011, 09:02 AM
#1
How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Hi,
My application is in VS2008 and coded in VB.net.
I have a datagridView(DGV) on one of my form.DGV contains a column of type DatagridViewComboboxColumn.I have another column of SrNo.
Consider Table1 to be the table from where my DatagridView is filled which contains following fields SrNo,Value1,Value2.
My requirement is i want to fill the values in my DatagridViewComboboxColumn from Table1.The DatagridViewComboboxColumn's combobox should contain values of columns Value1,Value2 of Table1.
Sample data of Table1
SrNo Value1 Value2
1 2 3
2 4 5
As data in datagridView is filled from Table1 the data of SrNo column of Table1 is also populated in one of the column of DGV.
Now my DatagridViewComboboxColumn combobox should contain the values of Value1 and Value2 of Respective SrNo.
Like Row one of my DGV has SrNo 1 as first value,so the Value1 and Value2 of SrNo 1 should be added to the row's DatagridViewComboboxColumn.
Select distinct Value1,Value2 From Table1 where SrNo=DGV.items(0,DGV.currentcell.rowIndex).value.Hope this Query willl make things more clear
Please Suggest.
-
October 11th, 2011, 09:27 AM
#2
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
That doesn't make a lot of sense. You want to WRITE fields from one table into another? That violates referential integrity rules (dup fields)
-
October 11th, 2011, 09:28 AM
#3
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
where did i said that i want to WRITE fields from one table into another.I said i want to retrieve from table1 and populate in DatagridView.
-
October 11th, 2011, 05:22 PM
#4
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
You can get 123 in a button, but not 1,2,3 unless you split them either in the db then bind, or not bind and load later.
-
October 12th, 2011, 01:23 AM
#5
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Sir im aware of how to fill the datagridview...
i want to fill the DatagridViewComboboxColumn.Please help how can i fill that combobox in DatagridView.DatagridViewComboboxColumn should have the values of columns Value1 and Value2 from Table1.
-
October 12th, 2011, 08:32 PM
#6
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Load the data after you read (and format) it.
-
October 13th, 2011, 06:13 AM
#7
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Only you can understand what solution you are providing..
-
October 13th, 2011, 07:17 AM
#8
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Are you getting anything in the combo box now? Are you wanting the two values to appear on the same line or different lines of the combo?
Always use [code][/code] tags when posting code.
-
October 13th, 2011, 08:33 AM
#9
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Just read this i think this will give clearer idea.
Please check.
I have a datagridview with three columns which is filled using Datareader. There is a DatagridViewComboboxcolumn in the datagridView.
I want this DatagridViewComboboxcolumn should also be filled using datareader.
Please suggest how can i add items to DatagridViewComboboxcolumn using Datareader. Below is the code that i have tried.
Here dr is SqlDatareader
I want to assign the value of Column3 to my DatagridViewComboboxcolumn
Datagridview.Rows.Add(dr("Column1").ToString, dr("Column2"),dr("Column3 "))
Please suggest me how can i add items to DatagridViewComboboxcolumn,that my only priority rest requirement i will do it myself.
thanks.
Last edited by Ehtesham Siddiqui; October 13th, 2011 at 08:59 AM.
Reason: Correction
-
October 13th, 2011, 10:04 AM
#10
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
So I take it the answer to my questions are No you are not getting anything and that you want only one column in the combo box?
C# sample
http://www.rustemsoft.com/vbbegin.asp#0
VB Sample
http://skaterpro.net/net_datagrid.htm
Last edited by DataMiser; October 13th, 2011 at 10:06 AM.
Always use [code][/code] tags when posting code.
-
October 13th, 2011, 05:45 PM
#11
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
I'm going to jump in (only to be ridiculed later). I believe you want to populate the ComboBox column's drop down items using Value1 & Value2. Essentially you have a two column DGV: first column has SrNo, second column has no value, yet, but the drop down items are Value1 & Value2 from that record (???). If I'm wrong stop reading now.
You can set the DropDown Items programatically, however, they will be the same for each row in the DGV (which doesn't fit your requirements). The only way I believe would be to:
1. catch the event each time the selection changes in the DGV
2. get the SrNo for that row in the DGV
3. get the Value1 & Value2 from your table which correspond to the SrNo
4. clear then add these values to the ComboBoxColumn's Items
5. may need some sort of DGV refresh/invalidate/etc. to redraw the dropdown items
This will set the Items for the entire DGVColumn, however, they should change every time you change rows.
-
October 13th, 2011, 07:49 PM
#12
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
He did say he wanted the value from column 3 so I think that means he only wants the one, though it is hard to tell when they do not give direct answers to questions
Always use [code][/code] tags when posting code.
-
October 14th, 2011, 12:49 AM
#13
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
so what is the solution to my query
-
October 14th, 2011, 07:55 AM
#14
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Look at the links I provided your answer is there
Always use [code][/code] tags when posting code.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|