Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
(bond_dataGridView.DataSource as DataTable).DefaultView.RowFilter = string.Format("[denom]= '{0}'", denom_comboBox.SelectedItem);

it only show value for some column where data is limited but for long data it give error help me....!
Posted
Updated 12-Dec-13 6:30am
v2
Comments
Member 10393648 12-Dec-13 12:49pm    
Cannot implicitly convert type 'int' to 'string'
it give error ....! :(
BillWoodruff 12-Dec-13 14:52pm    
It's very obvious you need to convert the ComboBox's SelectedItem to a 'string.

If that doesn't fix your problem, then, unless you give an example of "long data" that either won't convert to a string, or that breaks your query: we can't help you.

So why don't you just remove the single quotes from your RowFilter expression:
C#
(bond_dataGridView.DataSource as DataTable).DefaultView.RowFilter =(string.Format("[denom] = {0}", denom_comboBox.SelectedItem);
//                                                                                          ^---^

You were trying to compare an int to a string in your RowFilter expression, which is most probably not what you intended.

Regards,
— Manfred
 
Share this answer
 
v4
Comments
Maciej Los 12-Dec-13 14:56pm    
Good advice, Manfred, +5!
By The Way: there are known issues with denom_combobox.SelectedItem(), i'm afraid. I would prefer to get value from combobox into variable (using Int32.TryParse method) and check its value before passing it to RowFilter.
Manfred Rudolf Bihy 12-Dec-13 14:59pm    
That would be a good idea, thanks!
Maciej Los 12-Dec-13 15:04pm    
You're welcome ;)
Please, check LinkedIn account ;)
Karthik_Mahalingam 12-Dec-13 22:00pm    
good , neatly explained.
First of all, where did you put the value you need for the parameter?
For example:
C#
denom_comboBox.DataSource = YourDataSource;
denom_comboBox.DataValueField = "ColID";
denom_comboBox.DataTextField = "ColCode";
denom_comboBox.DataBind();

If you want to get the selected "ColID" then use
C#
denom_comboBox.selectedValue

If you want to get the selected text "ColCode" then use
denom_comboBox.selectedItem.Text

If you want to get the selected index then use
C#
denom_comboBox.selectedIndex
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 12-Dec-13 22:01pm    
Good
Did you try

(bond_dataGridView.DataSource as DataTable).DefaultView.RowFilter =(string.Format("[denom]= '{0}'", denom_comboBox.SelectedItem.ToString());
 
Share this answer
 
Comments
bowlturner 12-Dec-13 13:38pm    
Obviously it's a conversion problem, I was just suggesting one place to try to convert.
Maciej Los 12-Dec-13 14:58pm    
+5!
ToString() method could help resolve issue, but there still are quotes ;)
Please, read my comment to Manfred's answer.
you can try this.

C#
(bond_dataGridView.DataSource as DataTable).DefaultView.RowFilter =(string.Format("[denom]= '{0}'", 
 Convert.ToInt32(denom_comboBox.SelectedItem)
; if exceed try
C#
Convert.ToInt32(Combox.selectedItem);
 
Share this answer
 
v2
Comments
BillWoodruff 12-Dec-13 14:55pm    
The OP is defining a RowFilter, which is a string.
Try this:
(bond_dataGridView.DataSource as DataTable).DefaultView.RowFilter =(string.Format("[denom]= '{0}'", denom_comboBox.SelectedItem);
 
Share this answer
 
v3
Comments
Member 10393648 12-Dec-13 12:43pm    
Error 2 Cannot implicitly convert type 'int' to 'string'
it give error ....! :(
Richard C Bishop 12-Dec-13 12:54pm    
What datatype does your denom_combobox.SelectedItem provide?
BillWoodruff 12-Dec-13 14:53pm    
A ComboBox Item is always of Type 'Object, which is why it must be converted to some required useful format.
Member 10393648 12-Dec-13 13:16pm    
it provide itneger type value ....
Member 10393648 13-Dec-13 5:17am    
it work for some field but for large data it does't show records plz help me......!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900