Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to assign Different Datasource to DataGridViewComboboxColumn to Different Rows??
 

How to assign Different Datasource to DataGridViewComboboxColumn to Different Rows??

Hi,

in my c#.net 3.5WindowsApplication i have a datagridview, in that i have a DataGridViewComboboxColumn.
i want to assign diffarent datasource to that column based on row
suppose for 1,3,4 rows i want to assign one datatable as datasource
for 2 one table
and for 5th row someothere table
means each row have its own datasource
how can i achieve this???
what i tried is:

foreach (DataGridViewRow dr in dataGridView1.Rows)

if ((dr.Index == 0) || (dr.Index == 2) || (dr.Index == 3))

Respcol.DataSource = yesnoResp();

else if (dr.Index == 1)

Respcol.DataSource = emptranPwd();

}

Respcol.ValueMember =

columnType.Resp.ToString();


---------------------------------------------------------

private DataTable yesnoResp()

{

DataTable dt = new DataTable();

dt.Columns.Add("Resp");

dt.Rows.Add("YES");

dt.Rows.Add("NO");

return dt;

}

private DataTable emptranPwd()

{

DataTable dt = new DataTable();

dt.Columns.Add("Resp");

dt.Rows.Add("LOGIN");

dt.Rows.Add("NO");

dt.Rows.Add("ALL");

return dt;

}

enum columnType

{

Resp

};

but it always taking the final row datasource to all rows...... :(

how can i assign diffarent datasources for diffarent rows combobox columns???

please if you have any idea please share




Thanks In Advance
--Naren





{

  • Moved byHarry ZhuMSFTThursday, August 20, 2009 2:28 AM (From:Visual C# General)
  •  
Narendra Reddy Vajrala  Tuesday, August 18, 2009 4:28 PM
Hi.

It seems that this is impossible. I know that Infragistics Component can make such trick but not standard of VS...
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
Andriy a33ik Butenko  Wednesday, August 19, 2009 1:21 PM

One DataGridViewComboBoxColumn shares one datasource. By the way, if the comboboxcell value cannot be found in the datasource, this will cause a DataError.

You can implement this function in another way. You can use DataGridViewTextBox to display the value and two combobox to show the selected value.

When the row index of current cell is 0 or 2, display one combobox control in this cell. When leaving this cell, set the value of corresponding DataGridViewTextBoxCell to the combobox display value. You can also use another property of textboxcell to restore the valuemember.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, August 25, 2009 6:24 AM
Hi.

It seems that this is impossible. I know that Infragistics Component can make such trick but not standard of VS...
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
Andriy a33ik Butenko  Wednesday, August 19, 2009 1:21 PM

One DataGridViewComboBoxColumn shares one datasource. By the way, if the comboboxcell value cannot be found in the datasource, this will cause a DataError.

You can implement this function in another way. You can use DataGridViewTextBox to display the value and two combobox to show the selected value.

When the row index of current cell is 0 or 2, display one combobox control in this cell. When leaving this cell, set the value of corresponding DataGridViewTextBoxCell to the combobox display value. You can also use another property of textboxcell to restore the valuemember.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, August 25, 2009 6:24 AM

You can use google to search for other answers

Custom Search

More Threads

• Trouble adding an OLEDB TableAdapter to a DataSet in Visual Studio 2008
• Turn off intermittent DataSet updates to DataGridViews
• I have problem with VS.2005
• Searching a database using a query
• Access2000 Database(table) replicated to SQL 2000/2003 server
• DataGridCell, EditMode and DataSourcechanges?
• DataGrids and Checkboxes
• How to Unselect item of ListBox?
• Help with a Custom ComboBox Column
• SQL Server Table based Datagrid