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

Text box as Child control of GridViewLookupColumn

1 Answer 36 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shamjith
Top achievements
Rank 1
Shamjith asked on 02 Jan 2009, 12:47 PM
Hi,
        I am working on rad gridview for winforms. I have a grid with four columns. The first columns is an id field, second column a display field. The third column is a hidden field that has two possible values(lookup, user entry). Based on this the fourth column should show a drop down list or a text box. If the value of the third column is "lookup", we have to get the id value from the id column, query a table with the id and fill the drop down with the resultant values. If the value of the third column is "user entry", we have to show a text box there where user can enter values. Upto this i have done but the problem is, the text box seems to be in locked mode initially when tried to enter data in it. If we try to enter the data after clicking some other columns , then it works fine. I am listing the code below.


public

partial class Test : Form

 

 

{

 

DataTable dtMain;

 

 

 

DataTable dtChild;

 

 

 

public Test()

 

{

InitializeComponent();

SetTableData();

radGridView1.DataSource = dtMain;

}

 

 

private void CreateMainTable()

 

{

dtMain =

 

new DataTable("MainTable");

 

dtMain.Columns.Add(

 

new DataColumn("Id", typeof(System.Int32)));

 

dtMain.Columns.Add(

 

new DataColumn("Desc", typeof(System.String)));

 

dtMain.Columns.Add(

 

new DataColumn("Type", typeof(System.String)));

 

 

}

 

 

private DataTable CreateChildTable()

 

{

dtChild =

 

new DataTable("ChildTable");

 

dtChild.Columns.Add(

 

new DataColumn("Id", typeof(System.Int32)));

 

dtChild.Columns.Add(

 

new DataColumn("Value", typeof(System.String)));

 

 

 

return dtChild;

 

}

 

 

private void SetTableData()

 

{

CreateMainTable();

CreateChildTable();

 

 

DataRow dr = dtMain.NewRow();

 

dr[

 

"Id"] = 1;

 

dr[

 

"Desc"] = "FT Status";

 

dr[

 

"Type"] = "lookup";

 

dtMain.Rows.Add(dr);

dr = dtMain.NewRow();

dr[

 

"Id"] = 2;

 

dr[

 

"Desc"] = "UT Status";

 

dr[

 

"Type"] = "lookup";

 

dtMain.Rows.Add(dr);

dr = dtMain.NewRow();

dr[

 

"Id"] = 3;

 

dr[

 

"Desc"] = "Test";

 

dr[

 

"Type"] = "userentry";

 

dtMain.Rows.Add(dr);

 

 

DataRow childRow = dtChild.NewRow();

 

childRow[

 

"Id"] = 1;

 

childRow[

 

"Value"] = "Test1";

 

dtChild.Rows.Add(childRow);

childRow = dtChild.NewRow();

childRow[

 

"Id"] = 1;

 

childRow[

 

"Value"] = "Test2";

 

dtChild.Rows.Add(childRow);

childRow = dtChild.NewRow();

childRow[

 

"Id"] = 1;

 

childRow[

 

"Value"] = "Test3";

 

dtChild.Rows.Add(childRow);

childRow = dtChild.NewRow();

childRow[

 

"Id"] = 2;

 

childRow[

 

"Value"] = "New1";

 

dtChild.Rows.Add(childRow);

childRow = dtChild.NewRow();

childRow[

 

"Id"] = 2;

 

childRow[

 

"Value"] = "New2";

 

dtChild.Rows.Add(childRow);

}

 

 

private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)

 

{

 

 

 

}

 

 

private void FillCustomLookupData(GridViewLookUpColumn gridViewLookUpColumn, int customLookupId)

 

{

 

 

if (gridViewLookUpColumn != null)

 

{

 

 

//DataTable dtNew = dtChild.Select("Id=" + Convert.ToString(customLookupId));

 

 

 

DataView dv = dtChild.DefaultView;

 

dv.RowFilter =

 

"Id=" + Convert.ToString(customLookupId);

 

gridViewLookUpColumn.DataSource = dv.ToTable();

gridViewLookUpColumn.UniqueName =

 

"Value";

 

gridViewLookUpColumn.DisplayMember =

 

"Value";

 

gridViewLookUpColumn.DropDownStyle =

 

RadDropDownStyle.DropDownList;

 

}

}

 

 

private void radGridView1_CreateRow(object sender, GridViewCreateRowEventArgs e)

 

{

}

 

 

private void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)

 

{

}

 

 

private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)

 

{

 

 

RadTextBoxElement rtxtElement;

 

 

 

if (radGridView1.CurrentRow.Cells["Value"] == null)

 

 

 

return;

 

 

 

GridViewLookUpColumn gridViewLookUpColumn = ((Telerik.WinControls.UI.GridViewLookUpColumn)(radGridView1.CurrentRow.Cells["Value"].ColumnInfo));

 

 

 

if (radGridView1.CurrentRow.Cells["Type"].Value.ToString().Trim() == "lookup")

 

{

FillCustomLookupData(gridViewLookUpColumn,

 

Convert.ToInt32(radGridView1.CurrentRow.Cells["Id"].Value));

 

radGridView1.CurrentRow.Cells[

 

"ValuesBound"].Value = "1";

 

}

 

 

else

 

 

{

rtxtElement =

new RadTextBoxElement();

 

 

 

if (radGridView1.CurrentRow.Cells["Value"].CellElement != null)

 

{

 

 

if (radGridView1.CurrentRow.Cells["Value"].CellElement.Children.Count == 0)

 

{

rtxtElement.TextChanged +=

 

new EventHandler(rtxtElement_TextChanged);

 

radGridView1.CurrentRow.Cells[

 

"Value"].CellElement.Children.Add(rtxtElement);

 

}

radGridView1.CurrentRow.Cells[

 

"ValuesBound"].Value = "1";

 

}

}

}

 

 

void rtxtElement_TextChanged(object sender, EventArgs e)

 

{

 

}

 

 

private void radCheckBox1_Enter(object sender, EventArgs e)

 

{

radCheckBox1.BackColor =

 

Color.Beige;

 

}

 

 

private void radCheckBox1_Leave(object sender, EventArgs e)

 

{

radCheckBox1.BackColor =

 

Color.Red;

 

}

}

 


Please help me to solve this.

Regards
Shamjith T.H



       

1 Answer, 1 is accepted

Sort by
0
Shamjith
Top achievements
Rank 1
answered on 02 Jan 2009, 12:54 PM
Sorry. My mistake. Code is working fine.
Tags
GridView
Asked by
Shamjith
Top achievements
Rank 1
Answers by
Shamjith
Top achievements
Rank 1
Share this question
or