We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Lookup cell using databound grid

I have a currency cell that is a lookup into another table. The currency may be 15 for example, but I want it to display USD by looking that up in another table. This works fine if I make the cell a combobox and set the source to the currency table, and the display member to CurrencyName. However, I don''t want the grid to be editable. I don''t want it to drop down or be editable, but I do want it to select the row if the cell is clicked (so disabling it is out of the question). Anyone know what I can do? Maybe it should be a formula cell instead (can they do lookups?). Thanks! John

5 Replies

AD Administrator Syncfusion Team October 13, 2004 01:48 PM UTC

Probably the simplest things is to just use the combobox that works for you now and hide the button. You can make it readonly so it cannot be changed or disable it so it cannot be clicked. To hide the button, set style.ShowButton = GridShowButton.Hide for the column. For ReadOnly, set style.ReadOnly = true. To disable it, set style.Enabled = false.

JW John Wood October 13, 2004 02:09 PM UTC

There''s no other way to have a column ''lookup'' to another table and show a different field? Isn''t that a really common scenario for normalized tables? I''m surprised it''s not possible to have a static field that does that. Can I have a formula lookup in another table in the dataset?

AD Administrator Syncfusion Team October 13, 2004 02:40 PM UTC

The GridGroupingControl supports this type of celltype, but it is not currently available in GridDataBoundGrid as it relies on technology only available through the grouping engine. Our Formula engine currently does not support VLookUp and HLookUp. But it is straight forward to create your own custom formula which could do specific lookups. But using formula cells in a GridDataBoundGrid requires additional work as this type of grid does not store cell specific styles. (There is a KB on this.) It can be done, but would take addition coding. Another option is to handle the grid.DrawCellDisplayText event. There you can catch the foreign key value and swap it for the proper display value. Directly using the ComboBox celltype is the simplest way to do it. You could do what you want by setting its properties. If you want a celltype that does this, you could derive a celltype from the combobox celltype, hide its button and make sure it never becomes editable if you want a celltype to do explicitly this look up. But, you can effectively do the same thing with the existing ComboBox celltype just setting properties.

JW John Wood October 13, 2004 02:47 PM UTC

Yes a disabled combobox does do exactly what I need... the only problem is that you can no longer select the row when you click that disabled cell, which becomes a usability issue and difficult to explain to users. Thanks for your help though.

AD Administrator Syncfusion Team October 13, 2004 03:18 PM UTC

Do you have grid.ListBoxSelectionMode set to do the row selections? If so, then handling the grid''s MouseDown would allow you to select the row at that point.
private void gridDataBoundGrid1_MouseDown(object sender, MouseEventArgs e)
	int row, col;
	Point pt = new Point(e.X, e.Y);
	int disabledCol = this.gridDataBoundGrid1.Binder.NameToColIndex("Col1");
	if(this.gridDataBoundGrid1.PointToRowCol(pt, out row, out col, -1)
		&& 	col == disabledCol)
		this.gridDataBoundGrid1.CurrentCell.MoveTo(row, 1); //assumes 1 is not disabled

Live Chat Icon For mobile
Up arrow icon