여기서는 dataAdpaters 및 Dataset 테이블을 사용하여 데이터베이스에서 CboPorts ComboBox에 데이터를로드합니다. 이 부분은 내가 그것을 DataView를 = {System.Data을 어떻게 다시 널 (null)와 오는 유지하는 CboPorts.SelectedItem.Tostring() 메소드를 사용하여 CboPorts 콤보를 구문 분석하려고하는 곳은 아무런 문제데이터 바인딩 된 콤보 박스의 선택 값 받기
public void LoadPorts(string portpath)
{
//Loads Existing ClientGroups from specified tables
string tablename = portpath;
SqlConnection sqlConnectionCmdString = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Rick\Documents\Visual Studio 2010\Projects\Server\database\ClientRegit.mdf;Integrated Security=True;User Instance=True");
//Properly Defines the string for naming the table according to the systems naming scheme
string Command = "SELECT Port FROM [" + tablename + "]";
SqlCommand sqlCommand = new SqlCommand(Command, sqlConnectionCmdString);
SqlDataAdapter objDA = new SqlDataAdapter(sqlCommand);
DataSet dsGroups = new DataSet();
objDA.Fill(dsGroups, "dtGroup");
cboPorts.DataSource = dsGroups.Tables["dtGroup"];
cboPorts.DisplayMember = "Port";
cboPorts.ValueMember = "Port";
}
와 함께 작동합니다. 을 DataRowView} 내가 이상한 비주얼 스튜디오 익스프레스 버그를 데 디버거 값 인텔 감지
private void cboPorts_SelectedIndexChanged(object sender, EventArgs e)
{
string xmlpath = @"C:\[...]" + cboNetGuid.SelectedItem.ToString() + ".xml";
XElement main = XElement.Load(xmlpath);
//This is where it's supposed to parse the Selected Item of the combo box
string SelectedPort = cboPorts.SelectedItem.ToString();
//Linq query for searching IP address by ID Attributes
IEnumerable<XElement> searched =
from ip in main.XPathSelectElements("Row/ip_addresses")
where (string)ip.Attribute("id") == SelectedPort //<--Passes the Value Here
select ip;
//Get the Ip from the selected port number
foreach (string ips in searched)
{
Network_IP = ips.ToString();
}
//Linq Query to assign attributes to xml server data file
IEnumerable<XElement> SearchedAttr =
from proto in main.XPathSelectElements("Row/protocols")
where (string)proto.Attribute("id") == SelectedPort
select proto;
foreach (string protos in SearchedAttr)
{
lstproto = protos.ToString();
}
//Linq query for searching security requests
IEnumerable<XElement> SearchedSec =
from Secure in main.XPathSelectElements("Row/security")
where (string)Secure.Attribute("id") == SelectedPort
select Secure;
foreach (string Secur in SearchedSec)
{
Security = Secur.ToString();
}
//Linq query for searching created dates
IEnumerable<XElement> SearchedCret =
from created in main.XPathSelectElements("Row/creation_date ")
where (string)created.Attribute("id") == SelectedPort
select created;
foreach (string Cret in SearchedCret)
{
Created = Cret.ToString();
}
//Define Channeling Form for Log Synchronizations
//Adds the data to the form
cboIP.Items.Add(Network_IP);
cboIP.SelectedIndex = 0;
cboProtocols.Items.Add(lstproto);
cboProtocols.SelectedIndex = 0;
if (Security == "YES")
{
cboEncrypt.SelectedIndex = 0;
}
else if (Security == "NO")
{
cboEncrypt.SelectedIndex = 1;
}
}
오는이 계속 나는 무슨 일이 일어나고 있는지 확실하지 오전하지만이 작동하도록되어, 나는 왜 확실하지 않다 그러나 나는 나의 코드에서 설명 할 것이다. 이 방법을 처리 할 다른 방법이 있는지 확실하지 않습니다.
은 선택한 콤보 박스 항목입니까? – Ehsan
예, 값을로드합니다. 콤보 상자에서 해당 값 중 하나를 선택할 수 있어야합니다. – shawn
메신저 GetItemText 메서드를 사용하여 데이터 바인딩 테이블을 가져 오는 방법을 잘 모르겠다. cboPorts.GetItemText (MYDATAITEM); – shawn