|
Hi All,
I have a custom generic list defined with:
namespace DataLayer
{
public class ExportFile
{
private string _path;
private string _fileName;
public string Path
{
get { return _path; }
set { _path = value; }
}
public string FileName
{
get { return _fileName; }
set { _fileName = value; }
}
public ExportFile(string _path, string _fileName)
{
Path = _path;
FileName = _fileName;
}
}
}
Being populated like:
void xamDataBaseView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataRecord dr = xamDataBaseView.ActiveRecord as DataRecord;
if (dr != null)
{
DataRowView drv = dr.DataItem as DataRowView;
string _path = drv.Row.ItemArray[4].ToString();
string _name = drv.Row.ItemArray[1].ToString();
exportlist.Add(new ExportFile(_path, _name));
listboxExport.Items.Refresh();
}
}
But in the listbox on the UI the contents is shown as:
DataLayer.ExportFile
I'm not entirely sure what I'm doing wrong here. Why is it showing the Type and not the data in the exportlist ...
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
You need to override the ToString() and format the values to be displayed in the ToString(), if it is a ListBox type of control.
|
|
|
|
|
Hi Guy
when bind generic object to gui , u must get object from ur class, then assign listbox.items.add()
And what is this "exportlist" ? i'm assuming this is listbox,
then ur code must be '
exportlist.items.add(new object('' ,''))
thnaks
|
|
|
|
|
Ravenet wrote: exportlist.items.add(new object('' ,''))
Thats not even valid code, there is no constructor of Object which takes 2 char vales.
Ravenet wrote: thnaks
no thnaks!
|
|
|
|
|
Hey
i wrote a sample code regards his object.
thanks.
|
|
|
|
|
The answer is pretty simple, you should have to set the DisplayMember and ValueMember of the ListBox to the names of the properties on your ExportFile which you want to use for display and value.
In your case you might want FileName for the DisplayMember and the ValueMember - but you're free to use any properties of the object being put into the List.
|
|
|
|
|
Fantastic that is exactly what the doctor ordered.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi Gurus, I'm using VS2005, In that I've the following WebService code
What I need is I want to write a log to a Textfile. Just give me a suggestion how to write a log entry on the code as follows:
1) Class: ValidateImageAuthorization.cs
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
//using System.Web.Services.Configuration;
[WebService(Namespace = "http://webservice.imaging.yellowbook.com")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//added for testing
//[WebMethod(1,Random,10,10)]
public class ValidateImageAuthorization : System.Web.Services.WebService
{
public ValidateImageAuthorization()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
#region User accessable function
// Gets user info(userid,roles,displayname,application type)
// Returns session unique identifier to requested user
[WebMethod(EnableSession = true)]
public Response CreateAuthorization(Request UserInfo)
{
string _SessionIdentifier;
string _DbReturnMessage;
Response objReturn = new Response();
try
{
// create new session identifier
_SessionIdentifier = Guid.NewGuid().ToString();
// Submits data (user id,unique session id,roles info,Display Name) into imaging database
_DbReturnMessage = IsUserInfoAddedIntoDB(UserInfo,_SessionIdentifier);
// Check user info successfully submitted to imaging database or not
if (_DbReturnMessage == "Success")
{
//In case of successful database submission, returns unique session id with return code(0).
objReturn.SessionIdentifier = _SessionIdentifier;
objReturn.Message = "Success";
objReturn.Returncode = 0;
}
else
{
//any issue with database updation, returns blank session identifier with appropriate return code(-1) & appropriate error message
objReturn.SessionIdentifier = "";
objReturn.Message = _DbReturnMessage;
objReturn.Returncode = -1;
}
return objReturn;
}
catch (Exception ex)
{
// returns error message to the user while facing any issue with Web Service itself
objReturn.SessionIdentifier = "";
objReturn.Message = ex.Message;
objReturn.Returncode = -1;
return objReturn;
}
}
#endregion
#region function to submits user information into YB imaging database
// Gets session unique identifier,userid,roles and display name as input parameters
public string IsUserInfoAddedIntoDB(Request UserInfo, string SessionID)
{
string IsDataValid;
int CCRole = 0, SSNRole = 0;
SqlCommand cmd = null;
SqlConnection connection = null;
SqlDataReader reader = null;
//Check whether input parameters for database updation is valid or not
IsDataValid=IsInputDataValid(UserInfo);
//In case of all invalid input parameters, returns appropriate error message.
if (IsDataValid != "InputDataValid") return IsDataValid;
//Code commented for updating DB(i.e UniqueSessionID table) for SSN & CC information
////In case of all valid input parameters
////filter Roles fields and search for ImageCC & ImageSSN roles info out of that.
//for (int i = 0; i < UserInfo.Roles.Length; i++)
//{
// //setting CCRole=1 if user has got access to view Credit card information out of contract images
// if (UserInfo.Roles[i].ToLower() == "imagecc")
// {
// CCRole = 1;
// SSNRole = 0;
// i = UserInfo.Roles.Length - 1;
// }
// //setting SSNRole=1 if user has got access to view SSN information out of contract images
// else if (UserInfo.Roles[i].ToLower() == "imagessn")
// {
// CCRole = 0;
// SSNRole = 1;
// i = UserInfo.Roles.Length - 1;
// }
// //setting CCRole=0 and SSNRole = 0, if user has got access to view SSN information out of contract images
// else
// {
// CCRole = 0;
// SSNRole = 0;
// }
//}
//Comment Ends
//Code Added by Prasanna on 1-Aug-2007 for updating DB(i.e UniqueSessionID)for SSN & CC information
//Code Starts
//In case of all valid input parameters
//filter Roles fields and search for ImageCC & ImageSSN roles info out of that.
object objcc = "imagecc";
object objssn = "imagessn";
// converting all elements to lower case
for (int i = 0; i < UserInfo.Roles.Length; i++)
{
UserInfo.Roles[i] = UserInfo.Roles[i].ToLower().Trim();
}
// Sorting all elements of Roles Array
Array.Sort(UserInfo.Roles);
// Searching for imagecc and imagessn in Roles array.(If array has both elements)
//ImageCC, ImageSSN
if (Array.BinarySearch(UserInfo.Roles, objcc) > -1 && Array.BinarySearch(UserInfo.Roles, objssn) > -1)
{
CCRole = 1; SSNRole = 1;
}
else
{
//Searching for imagecc in Roles array.
//If array has imagecc and other elements and not imagessn
if (Array.BinarySearch(UserInfo.Roles, objcc) > -1)
{
CCRole = 1; SSNRole = 0;
}
//Searching for imagessn in Roles array.
//If array has imagessn and other elements and not imagecc
else if (Array.BinarySearch(UserInfo.Roles, objssn) > -1)
{
CCRole = 0; SSNRole = 1;
}
//If array has other than imagecc and imagessn elements
else
{
CCRole = 0; SSNRole = 0;
}
}
//Code Ends
//gets Stored procedure name from Web.Config file
string cmdString = ConfigurationManager.AppSettings["SPDetails"];
//gets SQL Connection string from Web.Config file
string connectionInfo = ConfigurationManager.AppSettings["DbConstr"];
connection = new SqlConnection(connectionInfo);
try
{
connection.Open();
cmd = new SqlCommand(cmdString, connection);
cmd.CommandType = CommandType.StoredProcedure;
//passing i/p parameters to Stored procedure for database submission
cmd.Parameters.Add("@USID", SqlDbType.VarChar).Value = SessionID;
cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = UserInfo.UserId;
cmd.Parameters.Add("@DISPLAYNAME", SqlDbType.NVarChar).Value = UserInfo.DisplayName;
cmd.Parameters.Add("@SSROLE", SqlDbType.Bit).Value = SSNRole;
cmd.Parameters.Add("@CCROLE", SqlDbType.Bit).Value = CCRole;
reader = cmd.ExecuteReader();
reader.Read();
//check whether stored procedure face any issue while inserting/updating data to imaging database
//Returns Errorcode=-1 in case of issues else returns 0
if (reader["ERRORCODE"].ToString() == "-1")
{
return reader["MESSAGE"].ToString();
}
else
{
return "Success";
}
}
catch (Exception e)
{
return e.Message;
}
finally
{
//Close the database connection
if (connection != null)
{
connection.Close();
}
//close the reader
if (reader != null)
{
reader.Close();
}
}
}
//Function validates input parameters for database submission
private string IsInputDataValid(Request UserInfo)
{
//check if Web service is not supplied any input parameters
if (
UserInfo.Roles.Length == 0 &&
UserInfo.UserId.Length == 0 &&
UserInfo.DisplayName.Length == 0 &&
UserInfo.ApplicationType.Length == 0
)
{
//return error message
return "Web Service is not supplied with any single input parameters";
}
//check length of Userid whether valid or not
if (UserInfo.UserId.Trim().Length == 0)
{
return "Input Parameter - Invalid UserID";
}
//check length of Display name whether valid or not
if (UserInfo.DisplayName.Trim().Length == 0)
{
return "Input Parameter - Invalid Display Name";
}
//check length of Roles info whether valid or not
if (UserInfo.Roles.Length == 0)
{
return "Input Parameter- Invalid Roles info";
}
else
{
//Check whether Array has not got string with space value
bool HasValue = false;
for (int counter = 0; counter < UserInfo.Roles.Length; counter++)
{
if (UserInfo.Roles[counter].Trim().Length != 0)
{
HasValue = true;
counter = UserInfo.Roles.Length - 1;
}
}
if (HasValue == false) return "Input Parameter - Roles must have least one value";
}
//check length of Application Type whether valid or not
if (UserInfo.ApplicationType.Trim().Length == 0)
{
return "Input Parameter - Invalid Application Type";
}
return "InputDataValid";
}
#endregion
#region web service input and output information structure
public class Request
{
public string UserId;
public string[] Roles;
public string DisplayName;
public string ApplicationType;
}
public class Response
{
public string SessionIdentifier;
public string Message;
public int Returncode;
}
#endregion
}
2) ASMX : ValidateImageAuthorization.asmx
]]>;
Raaj
|
|
|
|
|
Hey
There many way write log file.
So You must decide what i want to include within log file, then select a way.and write log file.
1.must use simple object
2.u must close file or stream immediately when u written
3.don't put garbage within log file
4.use the simple phrases.
that's all.
|
|
|
|
|
buddy,
try log4net.
******************************
I just want to
know everything
|
|
|
|
|
|
I'm hoping there's a more streamlined approach to this. In a form, I have 7 textboxes and a button. When the button is clicked, each textbox needs to be looked at to ensure it contains something. If the textbox is blank, I have a label on the forum to alert the user of such. Then I direct focus to the blank textbox. So far I've been doing it like this:
if (txt1.text == "")<br />
{<br />
ErrorLabel.text = "Enter something in txt1";<br />
txt1.focus();<br />
}<br />
else if (txt2.text == "")<br />
{<br />
ErrorLabel.text = "Enter something in txt2";<br />
txt2.focus();<br />
}<br />
else if (txt3.text == "")<br />
{<br />
ErrorLabel.text = "Enter something in txt3";<br />
txt3.focus();<br />
}<br />
else if (... and so on, and so on for all 7 textboxes)
Is there a way to do it with less code?
|
|
|
|
|
Realistically you should create a class that implements the data that you want, and then put a binding against the textbox. With a bit of the magic listed here[^] you can save yourself a lot of work keeping validation and items in sync.
|
|
|
|
|
Pete O'Hanlon wrote: With a bit of the magic listed here[^] you can save yourself a lot of work keeping validation and items in sync.
That's a great article. Do you know any similar approach available for web application ?
|
|
|
|
|
You could adapt it using techniques described in this[^] article.
|
|
|
|
|
if you don't want to go with databinding which is a good option, you can combine all the if statements:
if(txt1.Text=="" OR txt2.text=="" OR txt3.text="" OR ...)
{
ErrorLabel.text="All fields must be entered to continue";
}
Their still may be better options though.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Why dont you just use required field validators?
|
|
|
|
|
*Clicks the Back Button2*
"Please fill in all the fields to continue" >
The reason I've stopped using RequiredFieldValidators....
|
|
|
|
|
How about this:
<br />
<br />
foreach (var tb in new TextBox[] { txt1, txt2, txt3, txt4, txt5, txt6, txt7 }) {<br />
if (tb.Text == "") {<br />
ErrorLabel.text = string.format("Enter something in {0}", tb.Name);<br />
tb.Focus();<br />
break;<br />
}<br />
}<br />
<br />
It aint pretty, and I'd prefer data binding, but it'd work?
|
|
|
|
|
If you set required field validators when tabbing to each textbox it instantly does validation i dont see the issue perhaps ive misinterperted your query
A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty I am a Optimist
|
|
|
|
|
That's what I would do too... so it must be wrong somehow.
|
|
|
|
|
I'll give this a shot .. looks interesting
I'd do databinding, but not sure how. I'm still new at this. If I created the DB within Visual Studio I'd be able to do it, but it's created at runtime (SQL CE)
EDIT: I just tried it, and it worked great. Thanks!!!
modified on Friday, April 4, 2008 1:36 PM
|
|
|
|
|
Or set the Button's Enabled property
btn.Enabled = ( txt1.Text.Length > 0 ) && ... ;
|
|
|
|
|
i know this is quite the inapropriate place to ask but i am not getting any answers from the truevision site concerning the 6.5 and it's mousepick train of code. i tried it but the mouse keeps on picking the wall behind the meshes i had set to rotate.
what i am trying to say is i set a wall and three meshes before it to rotate that way if you click on one of the meshes an event will occur but the event keeps on happening to the wall instead. what should i do?
help please
|
|
|
|
|
anarchi23 wrote: what should i do?
sounds like A) you have not bitmasked your picking objects B) you have not cleared your events so they stay on the event stack C) you are unfamiliar with the environment and the confusion runs deeper D) you are unfamiliar with the language and the confusion runs even deeper still.
If you are not getting answers at the truevision forums, the answer may be at the core language, C#. Since I see you recently joined only to cross post, you aren't likely to get many answers, but you might if you phrased it better.
The process you are describing is a 3D problem, but the code that it is uses is obvious a language issue. Not understanding either means you aren't likely to even know which problem is which or where it should be. That is bad news. Brush up on your C# related to the activities being used to narrow this down to a 3D issue not a language use issue. Once you have that down, someone, though there are few of us here, may be able to help. There are very few 3D graphics programmers here and fewer still in C#.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|