Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Set the Default value for Combox present in DataGridview
 

Set the Default value for Combox present in DataGridview

Hi All,

I am using DataGridview and there is a Combobox column is present in the datagrid.

I am binding the DataGridViewComboboxcolumn with a DataSource.

DataGridViewComboBoxColumn cmbInstType = (DataGridViewComboBoxColumn)grdCashMemoDetails.Columns["grdCashMemoDetailsInstrumentType"];

DataTable instType = new DataTable(); "Value", typeof(int)); "Display", typeof(String)); "Cash"); "Card"); "DD"); "Cheque"); "Display"; "Value";

instType.Columns.Add(

instType.Columns.Add(

instType.Rows.Add(1,

instType.Rows.Add(2,

instType.Rows.Add(3,

instType.Rows.Add(4,

cmbInstType.DisplayMember =

cmbInstType.ValueMember =

cmbInstType.DataSource = instType;

Now I want to set the default selected value for the combobox as

grdCashMemoDetails.Rows[e.RowIndex].Cells[(

int)enmGridViewColumnIndex.InstrumentType].Value = 2; But this is not working.


Please guide me how to do this.

Gyanendar


Gyanendar  Thursday, July 16, 2009 9:46 AM
Where are you doing this code the sets the value property? The typical place is the DataGridView.DefaultValuesNeeded event.

Note that when bound to a DataSet, you might also consider the alternative of setting the DataColumn's DefaultValue property which you can do in code or even through the Visual Studio strongly-typed DataSet designer.
BinaryCoder  Friday, July 17, 2009 12:33 AM

Hi Gyanendar,

Could you please provide the error you met or why it does not work? You code is good, I cannot find which sentence is incorrect. This is a sample code:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcell.datasource.aspx.

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, July 17, 2009 1:28 PM

Thanks for the suggestion .

With little bit of modification ,Code is giving the desired response.

Gyanendar

Gyanendar  Monday, July 20, 2009 9:42 AM
Hi Gyanendar,

Would you mind sharing your answer? This will help others in this forum. Thanks.

Best regards,
Aland Li

Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, July 22, 2009 1:50 AM

Hi,

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Best regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, July 23, 2009 3:17 AM

You can use google to search for other answers

Custom Search

More Threads

• Binding Navigator - Enable/Disable Save Button
• Using ASP.NET style connection in VB.NET
• Visual Studio 2008
• Date validation in windows form. (Vb)
• Combobox and null value
• Custom DatagridviewColumn/Cell
• Updating Progress While Filling Dataset
• Populate a DropDownBox with certain info from Access
• DataGridView comboBox filter with two DataTables
• How do you actually get a "project-wide" dataset in VB ?