hi my name is vishal for 2 days i have been breaking my head on how to pass selected item of datas of listbox into listview of different column datas in c# windows forms with sql server 2008?. I have 2 list boxes in my form named:
frmGetSystemData.
1st listbox name:
lstIP,enabled:
true,Multi Column:
false,Selection Mode:
One and visible:
true.
2nd listbox name:
lstDialyzerID,enabled:
true,Multi Column:
false,Selection Mode:
One and visible:
true
i have one button control named:
btnUpdateDialyzer,enabled:
true,text:
Start Dialyzer Cleaning Process and visible:
true.
i have a listview control in same form named:
lvwConnections,enabled:
true,FullRowSelect:
true,GridLines:
true,MultiSelect:
false,visible:
true and View:
Details.
Given below is my c# code on how i populate my listboxes(
lstDialyzerID) and another listbox(
lstIP) in form(
frmGetSystemData):
private void frmGetSystemData_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
lstIP.Items.Clear();
SqlCommand hcd = new SqlCommand();
DataSet ms;
DataTable mt = new DataTable();
SqlDataAdapter mju = new SqlDataAdapter();
hcd = new SqlCommand("Select ManufacturerName,DCS_ip_address from Reprocess", conn);
mju = new SqlDataAdapter(hcd);
ms = new DataSet();
mju.Fill(ms, "Reprocess");
mt = ms.Tables["Reprocess"];
for(int j=0;j<mt.Rows.Count;j++)
{
MDIParent1 g=new MDIParent1();
if(mt.Rows[j].ItemArray[0].ToString()==g.sckClient.RemoteHostIP)
{
lstIP.Items.Add(mt.Rows[j].ItemArray[0].ToString()+"-"+mt.Rows[j].ItemArray[1].ToString());
}
}
lstDialyzerID.Items.Clear();
SqlCommand cmd = new SqlCommand();
DataSet ds;
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();
cmd = new SqlCommand("Select d.dialyserID,pn.patient_id,pn.patient_first_name,pn.patient_last_name from dialyser d,patient_name pn where d.closed_status=0 and d.deleted_status=0 and pn.patient_id=d.patient_id and pn.status=1", conn);
adp = new SqlDataAdapter(cmd);
ds = new DataSet();
adp.Fill(ds, "dialyser");
adp.Fill(ds, "patient_name");
dt = ds.Tables["dialyser"];
dt = ds.Tables["patient_name"];
for (int i = 0; i < dt.Rows.Count; i++)
{
lstDialyzerID.Items.Add(dt.Rows[i].ItemArray[0].ToString() + "|" + dt.Rows[i].ItemArray[2].ToString() + " " + dt.Rows[i].ItemArray[3].ToString() + "-" + string.Format("000" + dt.Rows[i].ItemArray[1].ToString()));
}
}
As you can see i have ManufacturerName and DCS_ip_address datas from table(
Reprocess) from sql server into listbox(
lstIP) in c# windows forms. I also have dialyserID,patient_first_name and patient_last_name from tables(
dialyser,
patient_name) from sql server into listbox(
lstDialyzerID) in c# windows forms.
What i want is after selecting an item from
lstIP(listbox) and
lstDialyzerID(listbox) and when i click button(
btnUpdateDialyzer) in my form(
frmGetSystemData) i want datas of ManufacturerName from
lstIP,dialyserID,patient first name and patient last name from
lstDialyzerID to appear in listview(
lvwConnections) with column name
DCS System containing datas of ManufacturerName(from
lstIP),
DialyzerID containing data of dialyserID(from
lstDialyzerID) and
Patient Name containing datas of patient first name and patient last name(from
lstDialyzerID).
Tell me how should i do to achieve my required output from
btnUpdateDialyzer(button) in my form:
frmGetSystemData. Can anyone help me/guide me please?! Tell me what modifications must i do in my button(
btnUpdateDialyzer) in form(
frmGetSystemData) to achieve my required output? Can anyone help me please?! Any help/guidance in solving of this problem would be greatly appreciated!