C# combo-box in grid view not populating correctly - c#

i have desktop application in which i am using data gridview control. i want to use a combo-box in each grid row that holds 2 items (Sale, Return). i am as far as single row concerns, i am not getting any issue but when i enter any other row, it shows me double comboboxes in each row and tripple for third row and so on.
second issue that i am facing is that i am not getting both of two items that i am trying to insert through items.add method. below is code that i am using to insert combobox column in grid
custCartGrid.Rows.Add();
GridRow = custCartGrid.Rows.Count-1;
DataGridViewComboBoxColumn dcom = new DataGridViewComboBoxColumn();
dcom.HeaderText = "Combobox";
dcom.Items.Add("Sale");
dcom.Items.Add("Return");
custCartGrid.Columns.Add(dcom);
please help me in this..

Related

Adding a checkbox to a databound DataGridView

I'm working with DataGridView in C#. I fill it with a table from database using BindingSource. After filling the DataGridView I need to add a row of checkboxes that should be first in the table, to enable data filtering in future.
I mean: for example after clicking "Load" button I get DataGridView filled with 4 columns of data and the first row should consists of checkboxes.
I confused. I use
DataGridViewCheckBoxCell checkCell = new DataGridViewCheckBoxCell();
SourceDGV.Rows.Add(checkCell);
I mean here:
But after clicking load button it says You can't add rows to databounded DataGridView
Sorry if ecxeption translated wrong, I translated it from Ukrainian.
Any help appreciated.
Am afraid, there is no concept of whole rows to be of some type(checkbox in your case) in DataGridView. It is other way around. You can have whole column to be of checkbox type. You'd use DataGridViewCheckBoxColumn for that.
Showing checkboxes in whole row even makes no sense for me: Assume you have data bounded Person object to the DataGridView. So there will be columns like Name, Age, Address. Now, on what basis you show checkbox in the row? How can a Name be converted to a bool(which is what checkbox needs as a value)?
One workaround I can think of would be, handle custom painting, If First row paint checkboxes over there and manually handle their click events. But am pretty sure it's not gonna be easy.

ASP.net Array List as a data source for Gridview

I am working with an asp.net grid view and i have used an array list of objects as a data source for this gridview.
every thing is ok but I faced some problems when i want to work on this gridview,
I want to to do the following:
Hiding a column
Change the column header text
Add a button to the gridview row and pass a value from the row to another page
thx in advance.
Hiding a column: are you using autogenerate columns? or did you add your own columns to the grid?
Change the column header text: open the grid columns editor (the little > icon on the upper right corner when you select the gridview)
Add a command column from the grid columns editor (step 2 above)
HTH
Jafar

getting data from combobox to a data grid view c#

I am using windows forms application. I have two combo boxes , comboA and comboB.I have a datagrid view with two columns. Now I have to populate the datagrid view, with selected item from comboA into first column of datagridview and selected item of comboB into the second column. Please suggest me
To be clear, When I select an item from comboA, it should be displayed in first column of datagridview. And similary when i select an item from comboB , it should be displayed in the second column of the datagridview.

Adding a dropdown box in Datagridview

I have a Datagridview which is showing some records from DB. Now I want to add a dropdown menu in between the columns of this Datagridview.
How could I achieve that? My DGrid is bound in runtime so I am not initializing every column here!
Help?
Use below code to add your Combobox Column at specific index of DataGridView
DataGridViewComboBoxColumn myCombo=new DataGridViewComboBoxColumn();
myCombo.HeaderText = "My Combo";
myCombo.Name = "myCombo";
this.dataGridView1.Columns.Insert(n, myCombo); // n is index

Problem in datagridviewComboBoxColumn

In my datagridview , when in click on datagridviewComboBoxColumn to populate its dropdownlist it not show me dropdown list for that i need to click 2 times. at first time it just focus to datagridviewComboBoxColumn and on second click it populate its dropdown. but i want to populate its dropdownlist on single click. please help me out. i am using c#.net (vs 2005)
The usual solution for this behaviour of the DataGridView is to set the EditMode property of the DataGridView to EditOnEnter.
There are some issues around using this approach, in particular that the row header is no longer available for row select. See Microsoft Connect here for more info on that issue.

Categories