This is a migrated thread and some comments may be shown as answers.

Can't edit contents of a GridViewLookUpColumn

2 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mtaber
Top achievements
Rank 1
mtaber asked on 31 Dec 2009, 06:52 PM
Forgive the cross-post, but I didn't realize until afterwards that GridViewLookUpColumn should be asked here instead.
I have a GridView that has three columns. The first is read only and named RuleKeyGuid. The second is called RuleKey, and the last is called KeyValue. I'd like for the second column to be a drop-down that suggests what the user might be looking for based on a data source. Here's what I entered:

System.Collections.IDictionaryEnumerator iterator = sortedRuleKeys.GetEnumerator();
while (iterator.MoveNext())
{
    GridViewRowInfo rowInfo = radGridView_RuleKeys.Rows.AddNew();
    rowInfo.Cells[0].Value = ((RuleKey)iterator.Value).RuleKeyGuid.ToString();
    rowInfo.Cells[1].Value = ((RuleKey)iterator.Value).keyName;
    rowInfo.Cells[2].Value = ((RuleKey)iterator.Value).keyValue;
}

((GridViewLookUpColumn)radGridView_RuleKeys.Columns[1]).AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
((GridViewLookUpColumn)radGridView_RuleKeys.Columns[1]).DropDownStyle = RadDropDownStyle.DropDown; 
 
DataTable dt = new DataTable(); 
dt.Columns.Add("RuleKey"typeof(string)); 
dt.Rows.Add("Mobile"); 
dt.Rows.Add("Business"); 
dt.Rows.Add("Fax"); 
((GridViewLookUpColumn)radGridView_RuleKeys.Columns[1]).DataSource = dt; 

If I make changes in the grid to cells in the third column, it works just fine. But I can't change the second column. When I type, it seems to be accepting whatever I'm typing, but when I hit enter, it goes away.

I have two problems here.
1) The value that I've manually set the cell to doesn't show up unless it's a member of the DataSource.
2) The user cannot enter any value other than what is in the DataSource. If they type something in, it doesn't "stick". You hit Enter and the value reverts to whatever it was before.

How do I go about addressing this? They both seem to be related. Is there a setting I'm missing or am I approaching this problem incorrectly?

2 Answers, 1 is accepted

Sort by
0
mtaber
Top achievements
Rank 1
answered on 31 Dec 2009, 09:47 PM
So after a lot of beating my head against the wall, I basically found my answer here:

http://www.telerik.com/community/forums/winforms/gridview/gridviewcomboboxcolumn-let-user-add-values-that-are-not-in-datasource.aspx#943039

I had also set the DisplayMember and ValueMember parameters, but was using a list as a datasource which also had some effect on this. If you can't figure out how to edit the contents of a GridViewLookUpColumn which is attached to a data source, use the link above. Works like a charm.

The only thing to keep in mind is that the code in the CellEndEdit event specifies the column, so make sure you set this to the column you're using or it won't work.



0
Svett
Telerik team
answered on 04 Jan 2010, 09:14 AM
Hi mtaber,

We are happy that you figured out the problem on your own. Let me know, if you need further assistance.

Greetings,
Svett
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
mtaber
Top achievements
Rank 1
Answers by
mtaber
Top achievements
Rank 1
Svett
Telerik team
Share this question
or