Click here to Skip to main content
15,919,028 members

Comments by jeremy12341234 (Top 16 by date)

jeremy12341234 16-May-12 12:24pm View    
Deleted
@Mewara: Hi Sandeep, the best possible solution I can think of is to have two different non-bound DataGridViewComboBoxColumns. I could use one as a "DisplayMember" and when that cell changes or cell end edits it could change the index to what would be a non-visible DataGridViewComboBoxColumn (ValueMember) to the same index.

What do you think? or do you know of any other boards or places that might know the answer.

Thanks!
jeremy12341234 15-May-12 13:04pm View    
I have created a solution and a database as a starting point example:

http://www.armadasoftwaresolutions.com/flagshipt.zip


I am populating the datagridview in an unorthodox manner. Maybe this is the reason:

public main()
{
InitializeComponent();

dgv1.DataError += new DataGridViewDataErrorEventHandler(dgv1_DataError);

DataGridViewComboBoxColumn cbCol = new DataGridViewComboBoxColumn();
cbCol.DefaultCellStyle.NullValue = "--Select--";
cbCol.FlatStyle = FlatStyle.Popup;
cbCol.DataSource = new functions_sqls().select("select distinct l.list_value vm, l.long_description dm from lists l where liststypesid = 5");
cbCol.DisplayMember = "dm";
cbCol.ValueMember = "vm";
dgv1.Columns.Add(cbCol);

DataTable mySelect = new functions_sqls().select("select top 5 p.lt_unit_of_measure_product from products p");

int irow = 0;
foreach (DataRow dr in mySelect.Rows)
{
dgv1.Rows.Add();
dgv1.Rows[irow].Cells[0].Value = int.Parse(dr[0].ToString());
irow++;
}
}
private void dgv1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
}
jeremy12341234 15-May-12 12:36pm View    
It displays the value member instead of the display member but when you click on the combobox in the datagrid it displays the display member. When you choose one of the display members and leave the datagridviewcombobox it displays the first displaymember but does not retain any new value.
jeremy12341234 15-May-12 12:31pm View    
I will not shout anymore. I will do anything you ask for a solution. I have been coding with databound comboboxes with C# for 6 years and databound comboboxes with other languages for at least 14 years. This is not my question.
jeremy12341234 15-May-12 12:29pm View    
The actual main code is:

new ov().add_ddl(this.Name, dgv1.Name, "products", "lt_unit_of_measure_product", "select l.list_value vm, l.long_description dm from lists l where l.liststypesid = 5 order by 2");
new ov().add_write(this.Name, dgv1.Name, "products", "lt_unit_of_measure_product");
new ov().add_setwidth(this.Name, dgv1.Name, "all", "all");
new ov().add_hide(this.Name, dgv1.Name, "usersidm");
new ov().add_hide(this.Name, dgv1.Name, "datetimem");

new functions_dgv().get("f",dgv1,this.Name,"products",false,false,false,"select '','',productsid,usersidm,datetimem,lt_unit_of_measure_product from products");

dgv1.DataError += new DataGridViewDataErrorEventHandler(dgv1_DataError);



Inside functions_dgv().get:

default:
sql1 = "";
sql1 = new ov().ovag("get", new object[] { "ddl", pFormName, pDGV.Name, pTable, Col.ToString() }).ToString();
if (sql1 != "")
{
DataGridViewComboBoxColumn cbCol = new DataGridViewComboBoxColumn();
cbCol.ValueType = System.Type.GetType("System.Int32");
cbCol.DefaultCellStyle.NullValue = "--Select--";
cbCol.FlatStyle = FlatStyle.Popup;
cbCol.DataPropertyName = "dpn";
cbCol.DataSource = new functions_sqls().select(sql1);
cbCol.DisplayMember = "dm";
cbCol.ValueMember = "vm";
cbCol.Name = Col.ToString();
pDGV.Columns.Add(cbCol);
}
else
{

DataGridViewTextBoxColumn dfCol = new DataGridViewTextBoxColumn();
dfCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
dfCol.Name = Col.ToString();
pDGV.Columns.Add(dfCol);
}
break;

It displays the value member instead of the display member but when you click on the combobox in the datagrid it displays the display member. When you choose one of the display members and leave the datagridviewcombobox it displays the first displaymember but does not retain any new value.