我正在为 Windows 应用程序编写一些代码,除了 IntelliSense 没有在某些单击事件范围内为我提供选项外,一切都很顺利。令人惊讶的是,当我在没有它的帮助的情况下对其进行编码时,它并没有在该代码行上给我任何红色波浪,所以我假设范围是好的。
我有两个表单,FormA
并且FormB
,一个按钮单击事件FormA
应该触发FormB
它的文本框,其中填充了它在运行附加的逻辑后收到的信息。我正在做的是
formSrchResult.txtSearchFirstName.Text = searchedInfo.FirstName;
formSrchResult.txtSearchLastName.Text = searchedInfo.LastName;
formSrchResult.txtSearchUsername.Text = searchedInfo.UserName;
formSrchResult.txtSearchEmail.Text = searchedInfo.Email;
formSearchResult
是 a 的对象,FormSearch(FormB)
并且searchedInfo
是具有存储数据的属性的类的对象,我希望在其中FormSearch
显示文本框。FormSearch
和都searchedInfo
被宣布为公开的,但是当我开始输入时
“formSrchResult。” + "ctrl + 空格"
IntelliSense 没有提供包含文本框和属性名称的列表。所以,我想知道是否有人对可能导致这种情况的原因有任何想法,我很想知道。顺便说一句,它的 Visual Studio 2012。
谢谢。
public class UserInfo
{
public int UserID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string UserName { get; set; }
}
那是存储搜索信息的类,下面是搜索方法的代码......
public UserInfo Search(string email)
{
UserInfo searchUserInfo = new UserInfo();
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("spListEverything", conn);
cmd.CommandText = "spListEverything";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Email", email);
SqlDataReader rdrSearch = cmd.ExecuteReader();
if (rdrSearch.Read())
{
//why do we need to convert the first name, last name etc to ToString
//when they are defined, in the database, as a string itself?
searchUserInfo.UserID = Convert.ToInt32(rdrSearch["UserID"]);
searchUserInfo.FirstName = rdrSearch["FirstName"].ToString();
searchUserInfo.LastName = rdrSearch["LastName"].ToString();
searchUserInfo.UserName = rdrSearch["UserName"].ToString();
searchUserInfo.Email = rdrSearch["Email"].ToString();
}
else
{
// "Sorry, no match found";
}
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
return searchUserInfo;
}
下面是我对 Intellisense 没有帮助的 btnClick 事件的编码
private void btnSearch_Click(object sender, EventArgs e)
{
string email = txtSearchEmail.Text.ToString();
Manage myManage = new Manage(); //to call the search function
FormSearchResult formSrchResult = new FormSearchResult();//to put the vlaues in the textboxes in that form
UserInfo searchedInfo = myManage.Search(email);
//the search function is not working properly. No value is returned to be stored
//in the userInfo object
//Here for some reason my intellisense is not providing options.
formSrchResult.txtSearchFirstName.Text = searchedInfo.FirstName;
formSrchResult.txtSearchLastName.Text = searchedInfo.LastName;
formSrchResult.txtSearchUsername.Text = searchedInfo.UserName;
formSrchResult.txtSearchEmail.Text = searchedInfo.Email;
txtSearchFirstName.Enabled = false;
formSrchResult.ShowDialog();
}