|
This Is my Main Combo Code
To populate
public static void PopulateMainCombo( ComboBox Combo, string ConnectionString, string TableName, string TextField, string ValueField, string DefaultValue )
{ Combo.DataSource = null;
string Query="select * from " + TableName;
Query = Query + " order by " + TextField;
Combo.DataSource=DataManager.ConnectingForCombo(ConnectionString,Query,TableName);
Combo.DisplayMember = TextField;
Combo.ValueMember = ValueField;
}
private void cmbMainDiagnosis_SelectedIndexChanged(object sender, System.EventArgs e)
{
bool blnVisible;
blnSubDiagnosis=false;
int intSelectedValue;
intSelectedValue=(int) this.cmbMainDiagnosis.SelectedValue;
cmbSubDiagnosis.Visible=false;
cmbSubSubDiagnosis.Visible=false;
blnVisible=Diagnosis.SetDiagnosisCombos(intSelectedValue,this.cmbSubDiagnosis,"tblsubdiagnosis_mas","strSubDiagnosisDesc","intMainDiagnosisCode","0");
blnSubDiagnosis=blnVisible;
if (blnVisible==true)
{
cmbSubDiagnosis.Visible=true;
}
else
cmbSubDiagnosis.Visible=false;
}
/////////////////////////////////////////////////////////////////////////////
and this is my Second Combo that is cmbsubDiagnosis on change of which my third combo that is cmbSubSubDiagnisis is to be populated.
////////////////////////////////////////////////////////////////////////////
private void cmbSubDiagnosis_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (blnSubDiagnosis==true)
{
bool blnVisible;
int intSelectedValue;
intSelectedValue=(int)this.cmbSubDiagnosis.SelectedValue;
cmbSubSubDiagnosis.Visible=false;
blnVisible=Diagnosis.SetDiagnosisCombos(intSelectedValue,this.cmbSubSubDiagnosis,"tblsubsubdiagnosis_mas","strSubsubDiagnosisDesc","intSubDiagnosisCode","0");
if (blnVisible==true)
{
cmbSubSubDiagnosis.Visible=true;
}
else
cmbSubSubDiagnosis.Visible=false;
}
}
///////////////////////////////////////////////////////////////////////////
and this is the function i use to puplate 2nd and 3 rd combo
///////////////////////////////////////////////////////////////////////////
public static bool SetDiagnosisCombos(int paramDiagnosisCode,ComboBox Combo,string TableName, string TextField, string ValueField, string DefaultValue )
{
String ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
Combo.DataSource = null;
String query = "select * from "+ TableName +" where "+ ValueField + " = " + paramDiagnosisCode;
DataTable Dt = DataManager.ExecuteQuery(ConnectionString, query, TableName );
if (Dt.Rows.Count!=0)
{
Combo.DataSource=Dt;
Combo.DisplayMember = TextField;
Combo.ValueMember = ValueField;
Combo.SelectedIndex = -1;
return true;
}
else
return false;
}
pls i am struggling since morning. Help me out pls. the problem comes at the bold points an exception is thrown which says additional information required
Monica
|
|
|
|
|
And what goes wrong ?
=(int)this.cmbSubDiagnosis.SelectedValue;
Is it possible that selectedValue is a string and you need Convert.ToInt16 instead of the cast ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
yes exactly the problem comes here.
what to do next
|
|
|
|
|
1. Change (int) to Convert.ToInt32( (like I said )
2. Step through the debugger in future to see what's going on when you've got a line that blows up
3. Next time you ask a question, if you know where the code blows up, then give us the code, and either way, tell us what the error is you're getting.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Its Still giving error at the same point and the error is
An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll
Additional information: Specified cast is not valid.
|
|
|
|
|
Step 2 - use the debugger to find why the Value can't cast to a number.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
when i used the debugger it shows that the selectedvalue has
"System.Data.DataRowView" value that is why its not converting it but what is the solution to it.
|
|
|
|
|
OK, so that's what you need to cast it to, and then get the value out of it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Casting to Int32 is also not working . It is giving same error
Is there any other way to achive my aim.Now where should i look. I am doing nothing different. Is there any other way to fill the combo with the rows from table with their code as value member.
or is there any otehr event which i can use.
|
|
|
|
|
Instead of casting to Int32 you have to first cast to System.Data.DataRowView. If you have this you can use its indexer to access the element you need. After that cast this element to Int32 and you are done.
|
|
|
|
|
how to do that can u pls explain i am new to C#
|
|
|
|
|
are you getting this problem only when the form is loading??
Afzal Hassen
|
|
|
|
|
As Im really in a hurry here just a small snippet:
DataRovwView drv = (DataRowView)this.cmbSubDiagnosis.SelectedValue;
int myIntValue = (int)drv[IndexOrNameOfTheColumnYouWishToAccess];
|
|
|
|
|
Your core problem is that you're shoving a datarowview into the value, the problem really is when you set the data source. You need to tell the combo which property to use to set the value for each row. The problem has nothing to do with the event. You have a datarowview in the value, you cannot magically turn it into an int, you need to either get it out as a datarowview ( which is what it is ) and then work out where your number is or, preferably, you need to fix the code that sets the datasource, so that it does in fact contain an int as you were hoping.
In general, these 'please help me, something blows up' posts are useless, look how long it took us to get to the heart of the problem. You should learn to use your debugger. You'll get your answer a lot quicker if you post something like 'this line throws an invalid cast exception and the value in the row that I'm trying to cast is a datarowview.' A few seconds in the debugger will tell you that, and as you learn C#, that's the path you'd follow to fix the problem, by first knowing what it is.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks
i will try to follow ur instructions .
monica
|
|
|
|
|
I know you take a performance hit if you make your methods virtual, but do you take a similar hit when you use abstract methods
|
|
|
|
|
Abstract methods are also virtual, it's just that they don't have any implementation in the base class. If you look into the generated IL, you'll see that they are declared virtual (plus abstract) and that method calls are translated to callvirt, which is IL speak for calling a virtual method.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I have a URL that I can open in the browser, but System.Uri removes a slash when it encounters an extra http: in the URL.
Here is the URL:
http://citeseer.ist.psu.edu/rd/55811103,124,1,0.25,Download/http://citeseer.ist.psu.edu/cache/papers/cs/1473/http:zSzzSzmaui.theoinf.tu-ilmenau.dezSzforschungzSzlinkszSz..zSzdoczSzhybrid_automata.pdf/alur92hybrid.pdf
System.Uri changes the above URL to (notice that http:// after Download is changed to http:/)
http://citeseer.ist.psu.edu/rd/55811103,124,1,0.25,Download/http:/citeseer.ist.psu.edu/cache/papers/cs/1473/http:zSzzSzmaui.theoinf.tu-ilmenau.dezSzforschungzSzlinkszSz..zSzdoczSzhybrid_automata.pdf/alur92hybrid.pdf
As a result, I get NameResolution exception when making HttpWebRequest.GetResponse() calls.
|
|
|
|
|
It assumes that you were wrong as it may not come 2 httpS in the url,
you may resolve this by sending it as a query string ,if you own this site.
|
|
|
|
|
|
string aa = "\document\test";
aa = aa.Replace("\", "\\"); --- this line C# doesn't like it??
I want to replace '\' in string aa to "\\". How to do it?
|
|
|
|
|
You have to escape your chars
Alex Korchemniy
|
|
|
|
|
I suspect the problem is that \d and \t are valid escape values, so you've not realised the problem. To put a \ in your string, either put two or, ( my preferred option ), use @. With @ at the start, everything is literal, the only escape is double quotes to do quotes.
string aa = "\document\test";
The value here is ocument test, where the spaces are a tab
string aa = @"\document\test";
string aa = "\\document\\test";
These both set the string as you'd expect
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If you have it already and want it to be replaced now,you may use the StringBuilder class that will assure that it's been replaced.
|
|
|
|
|
string aa = @"\document\test";
aa = aa.Replace(@"\", @"\\") ;
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|