Answered by:
Set DatagridviewComboBoxColumn Default Value

Question
-
Hi
I have a datagridview in that i have a comboboxColumn
Now i want to set the default value for that so that each newly added row have that default value of the combobox
there is no for User to select the value Only the user has to do is change the value accordingly
Means if the ComboBox values are DR. & Cr.
Then Dr. is default value for that combo in the datagridview column
Thanks a lot in advance
Tuesday, March 14, 2006 5:12 AM
Answers
-
Just handling the cellFormatting event:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0) // your combo column index
{
e.Value = "Dr.";
}
}
Friday, January 19, 2007 11:54 AM
All replies
-
Plz Somebody give me the direction for my problem
That how we can assign an default value to the COmboBoxCOlumn of Datagridview.
Saturday, March 18, 2006 9:00 AM -
It can be done without a line of code in the DataSet Designer. Just set a default value for the column that is a source of data for your combobox.Saturday, March 18, 2006 11:40 AM
-
You may set as follow;
DataGridViewComboBoxColumn
salColumn = new DataGridViewComboBoxColumn();salColumn.DefaultCellStyle.NullValue = ((
GOR)gor.Items[0]).GorName;Wher GOR object is as follow:
public
class GOR{
private String gorName; private String gorValue;{
this.gorName = gorName; this.gorValue = gorValue;}
public String GorName{
get { return gorName; } set { this.gorName = value; }}
public String GorValue{
get { return gorValue; } set { this.gorValue = value; }}
}
Tuesday, December 26, 2006 7:06 AM -
Just handling the cellFormatting event:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0) // your combo column index
{
e.Value = "Dr.";
}
}
Friday, January 19, 2007 11:54 AM -
Hi Thank You for the post .
This solved my problem
- Proposed as answer by Shankar Janakiraman Friday, October 22, 2010 11:27 AM
Thursday, July 31, 2008 3:35 PM -
Dim dgvCell1 As System.Windows.Forms.DataGridViewComboBoxCell
Dim dgvCell2 As System.Windows.Forms.DataGridViewComboBoxCell
'Here my Column1 and Column2 are DataGridViewComboBox
'myDataGridViewControlName - is the Name for my DataGridViewControl
dgvCell1 =
CType(myDataGridViewControlName.Rows(0).Cells(1), Windows.Forms.DataGridViewComboBoxCell)
dgvCell2 =
CType(myDataGridViewControlName.Rows(0).Cells(2), Windows.Forms.DataGridViewComboBoxCell)
'dgvCell1.Selected = True
If Not dgvCell1.Items.Count = 0 Then
dgvCell1.Value = dgvCell1.Items(0)
End If
If Not dgvCell2.Items.Count = 0 Then
dgvCell2.Value = dgvCell2.Items(0)
End If
Hope this works....
Friday, October 22, 2010 11:31 AM -
private void dgvVisita_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 5)
{
e.Value = "0";
}
}I used this but everytime I select a number from the ComboBox, It returns to "0".
Tuesday, January 17, 2012 2:18 AM