Groups | Blog | Home
all groups > dotnet windows forms databinding > november 2004 >

dotnet windows forms databinding : Datagrid Combobox column datasource problem


v-jetan NO[at]SPAM online.microsoft.com (
11/4/2004 9:41:59 AM
Hi Srikanth,

For this issue, I have replied you in
microsoft.public.dotnet.framework.windowsforms.controls group, please check
there. I will follow up with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Srikanth
11/4/2004 3:51:20 PM
Hi,
I am trying to set the datasource for a Combobox column of a Datagrid to
a relationship of a Datatable:

this.GoodsColumn.ColumnComboBox.DataSource =
voyageDataset1.tblConsignment.DefaultView;
this.GoodsColumn.ColumnComboBox.DisplayMember =
"tblConsignmenttblGoods.strGoodsDesc1";
this.GoodsColumn.ColumnComboBox.ValueMember =
"tblConsignmenttblGoods.intLineItemNo";

This throws an exception saying "tblConsignmenttblGoods.intLineItemNo is
neither a DataColumn nor a DataRelation for table tblConsignment."

The error is getting thrown in the custom 'DataGridComboBoxColumn' class
'GetColumnValueAtRow' method:

protected override object
GetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum)
{
object s = base.GetColumnValueAtRow(source, rowNum);
DataView dv = (DataView)this.ColumnComboBox.DataSource;
int rowCount = dv.Count;
int i = 0;

//if things are slow, you could order your dataview
//& use binary search instead of this linear one
while (i < rowCount)
{
if( s.Equals( dv[i][this.ColumnComboBox.ValueMember]))
break;
++i;
}

if(i < rowCount)
return dv[i][this.ColumnComboBox.DisplayMember];
}

But, if I do the same thing for a standalone Combobox:

comboBox1.DataSource = voyageDataset1.tblConsignment.DefaultView;
comboBox1.DisplayMember = "tblConsignmenttblGoods.strGoodsDesc1";
comboBox1.ValueMember = "tblConsignmenttblGoods.intLineItemNo";

This works.

I just dont understand what I am doing wrong.

Any help is appreciated.
Thanks in Advance,
Srikanth

AddThis Social Bookmark Button