How to Show a default value in GridViewlookUpColumn for windows applications

4 posts, 0 answers
  1. rajesh
    rajesh avatar
    13 posts
    Member since:
    Oct 2007

    Posted 16 Feb 2009 Link to this post

    Dear All,

    I am using Telerik Q3 controls.

    May i know how to show a default value in the radgridview LookUpcolumn when the data was binding to that.

    Thanks & Regards,
    Rajesh
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 17 Feb 2009 Link to this post

    Hi Rajesh,

    I am not sure if I understand this question correctly. You can set a default value when adding a new row by processing the DefaultValuesNeeded event. Consider the following code snippet:

    void radGridView1_DefaultValuesNeeded(object sender, GridViewRowEventArgs e) 
        e.Row.Cells["Value1"].Value = 1; 
     

    If your column contains null values, you could specify a default value when opening e new editor. This can be done through processing the CellBeginEdit event. Here is a sample:

    void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
        if (e.ColumnIndex == 0) 
        { 
            RadComboBoxEditor editor = (RadComboBoxEditor)this.radGridView1.ActiveEditor; 
            editor.SelectedIndex = 0; 
        } 

    I hope this helps. If you have any questions, do not hesitate to write me back.

    Best wishes,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. rajesh
    rajesh avatar
    13 posts
    Member since:
    Oct 2007

    Posted 17 Feb 2009 Link to this post

    Hi Jack,

    Thanks for your reply.

    I have a requirement like first i am binding a datatable to the datasource of the rad grid and then i m assignina a new  set of values for the GridviewLookUpColumn as in the given code.so now i need to show a default value in this column.

    the event defaultvaluesneeded isnt firing even




    GridViewLookUpColumn gvLookup1 = (GridViewLookUpColumn)radgrid1.Columns["Reason"];
                gvLookup1.HeaderText = "Reason";
                gvLookup1.FieldName = "Reason";
                gvLookup1.DataSource = ds.Tables[1];
                gvLookup1.DisplayMember = "EMPName";
                gvLookup1.ValueMember = "EMPCode";
                gvLookup1.Width = 160;
                radgrid1.AutoScroll = true;

    can you please help me in this regard.

    Thanks
    Rajesh
  5. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 18 Feb 2009 Link to this post

    Hi rajesh,

    The DefaultValuesNeeded event is fired only when adding a new row.

    You can set cell values at any time by iterating through the Rows collection. Here is a sample:

    foreach (GridViewDataRowInfo row in this.radGridView1.Rows) 
        row.Cells["Value1"].Value = 10; 

    You can also set the a default text when there is no value in the cell. This can be done when processing the CellFormatting event. Take a look at the code snippet below:

    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
        if (e.CellElement.ColumnInfo.HeaderText == "Value1"
        { 
            GridDataCellElement dataCell = e.CellElement as GridDataCellElement; 
            if (dataCell != null
            { 
                if (dataCell.Value == null || dataCell.Value == DBNull.Value) 
                { 
                    dataCell.Text = "null"
                } 
            } 
        } 

    Please, tell me if I misunderstood your question and if you need any further assistance.

    All the best,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top