Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid combo box selection not showing in datagrid

Status
Not open for further replies.

jl3574

Programmer
Joined
Jun 5, 2003
Messages
76
Location
CA
i have a datagrid with a combo box added in it's columns . the combobox pulls values from a database in it's dropdownlist fashion. my problem is that when i pick a select on the combo box it doesn't stay on the cell after selected almost as if the combobox is on top of the cell and after u select an item and click next cell or column the select dissapear?
=================================================
//this part pulls from db and puts it in an arraylist
SqlConnection dbConn = new SqlConnection(strConn);
dbConn.Open();
SqlCommand SC = new SqlCommand("Select FirstName From Employee Order By FirstName",dbConn);
SqlDataReader SR=SC.ExecuteReader();
while(SR.Read())
{
temp=SR.GetString(0).TrimEnd();
EmployeeCell.Add(temp.ToString());
//pulling the first names and add to the arraylist object
}
dbConn.Close();
SR.Close();

//creating combo box
ComboBox EmployeeCB=new ComboBox();
EmployeeCB.Cursor=System.Windows.Forms.Cursors.Arrow;
EmployeeCB.DropDownStyle=System.Windows.Forms.ComboBoxStyle.DropDownList;

//defining the column and added a column name employee
DC=new DataColumn("Employee");
DC.DataType=System.Type.GetType("System.String");
DT.Columns.Add(DC);
EmployeeCB.Dock=DockStyle.Fill;

//creating table style and mapping
DataGridTableStyle NewTableStyle;
NewTableStyle.MappingName=DT.TableName;//mapping datagrid
//myDatagrid is the Datagrid i'm using in my form
myDataGrid.TableStyles.Add(NewTableStyle);

//adding combo box to the first column
DataGridTextBoxColumn dgtb=(DataGridTextBoxColumn)Weld_DataGrid.TableStyles[0].GridColumnStyles[0];
dgtb.TextBox.Controls.Add(EmployeeCB);

EmployeeCB.DataSource=new ArrayList(EmployeeCell);
//adding employee array list to combo box

/////////////////////////////////////////////////////////
so this example shows a datagrid with one column with the combobox in the first column...again the problem the combobox select does not stay
pls help
thx.
 



iSelIndex shoud be apublic variable

int iSelIndex =-1;//in the public variables declaartion

in selectedindex changed event get the selected index

something like this iSelIndex = combobox1.SelectedIndex

and then use

this in the cell leave event

combobox1.SelectedIndex = iSelIndex
 
i can get the name of the selection in the combobox like..
string dropdownSelection=ComboBox1.Text.ToString().TrimEnd();

put say i make a selection in the combobox that's in the first column and say it's a selection of name and i pick the second selection and it's "john" i can get the name "john" from the string dropdownselection var
but then say i click tab to move to next column
in the first column the selection "john" doesn't show up in that first column cell

i used the event handler combobox1

EmployeeCB.SelectionChangeCommitted+=new System.EventHandler(cmbchanger);
i'm not sure if i get what ur trying to show me? i'm gettin confused a bit...
but i still can't get it to work!!?help still thx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top