@ddanbe Thank you but I am not aware of tag property can you please give some highlights on that. Well This the code by which the I generation the output shown in figure -
GroupBox[] grpBox;
CheckBox[] dayCheckBox;
int grpposition = 40;
public step2(List<string> list)
{
InitializeComponent();
int x = list.Count;
grpBox = new GroupBox[x];
for (int i = 0; i < x; i++)
{
grpBox[i] = new GroupBox();
grpBox[i] = new GroupBox();
grpBox[i].Name = "gpBox" + Convert.ToString(i);
grpBox[i].Text = list[i];
grpBox[i].Location = new Point(5, grpposition);
grpBox[i].Width = 500;
grpBox[i].Height = 75;
this.Controls.Add(grpBox[i]);
dayCheckBox = new CheckBox[7];
String[] dayName={"Sun","Mon","Tue","Wed","Thr","Fri","Sat"};
for (int j = 0; j < 7; ++j)
{
dayCheckBox[j] = new CheckBox();
dayCheckBox[j].Name = "radio" + Convert.ToString(j);
dayCheckBox[j].Text = dayName[j];
dayCheckBox[j].Width = 50;
dayCheckBox[j].Location = new System.Drawing.Point(70 * j, 25);
grpBox[i].Controls.Add(dayCheckBox[j]);
//dayCheckBox[i].CheckStateChanged += new System.EventHandler(dayCheckBoxCheckedChanged);
}
grpposition += 80;
}
Hello Every body
I am standing on a cross road with a doubt which way is the correct way. As you all are seeing the image Groupbox and CheckBoxes all are dynamically created. What I am confused about If user select Sun Tue and Fri from XII2013SIF01 and Mon Tue Wed and Thr from XII2013SIG02 how I can pass these check boxes value to Step 3 Form on button click. In Step 3 form I need to identify days by their Group name because according to that processing will be done. What technique will be best for me please give some guidance/suggestion or advice.
How can Pass List to a constructor, I trying like this
private void button1_Click(object sender, EventArgs e)
{
step2 st2 = new step2(list);
}
But what to write in constructor definition
public step2()
{
InitializeComponent();
}
Any suggestion is welcome
}
list = new List<string>();
}
private void BatchBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox batchBox = (CheckBox)sender;
//Here I want to store name of checkbox in array
if (batchBox.Checked == true)
{
list.Add(batchBox.Text);
}
}
private void button1_Click(object sender, EventArgs e)
{
foreach(string prime in list) // Loop through List with foreach
{
Console.WriteLine(prime);
}
}
Done
Thank you DDANBE and Tinstaff
I am trying that only but not finding the correct way of implementing the code for list
See what I have done and what messup I have done
// Added this line in class level
List<CheckBox> chks;
// Added this line inside constructor
chks = Controls.OfType<CheckBox>().ToList();
int total_batch = 1;
private void BatchBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox batchBox = (CheckBox)sender;
//Here I want to store name of checkbox in array
List<string> names = chks.Where(batchCheckBox => batchCheckBox.Checked).Select(batchCheckBox => batchCheckBox.Name);
if (batchBox.Checked == true)
{
total_batch++;
}
else
{
}
}
But getting this error
Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string>' to 'System.Collections.Generic.List<string>'. An explicit conversion exists (are you missing a cast?) D:\TimeTable\TimeTable\main.cs 138 34 TimeTable
Hello Everybody
How can store name of dynamically created checkbox in a String array when I don't know how many checkbox will user select at runtime.
Say I have 10 dynamic checkboxes and out of 10 user select 6 checkboxes randomly now how can get the name of those selected checkboxes and store them in a String array.
I know how to use event handler on dynamic check box but confused how to declare Straing array when I don't know what will be be size of an array.
Here what I have done till now -
private void CheckBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
//Label myLabel;
String str = null;
if (c.Checked == true)
{
str = c.Text;
gpBox[gpcount] = new GroupBox();
gpBox[gpcount].Name = "gpBox" + Convert.ToString(count);
gpBox[gpcount].Text = str;
gpBox[gpcount].Location = new Point(5, gpposition);
gpBox[gpcount].AutoSize = true;
this.Controls.Add(gpBox[gpcount]);
aCommand3 = new OleDbCommand("select * from batch_tbl where batch_branch LIKE '" + str + "'", main_connection);
aAdapter3 = new OleDbDataAdapter(aCommand3);
ds3 = new DataSet();
aAdapter3.Fill(ds3, "app_info");
ds3.Tables[0].Constraints.Add("pk_bno", ds3.Tables[0].Columns[0], true);
int batch_count = ds3.Tables[0].Rows.Count;
batchCheckBox = new CheckBox[batch_count];
//filling the groupbox with batch code by generating dynamic checkboxes
for (int j=0; j < batch_count; ++j)
{
batchCheckBox[j] = new CheckBox();
batchCheckBox[j].Name = "batch" + Convert.ToString(k);
batchCheckBox[j].Text = ds3.Tables[0].Rows[j][1].ToString();
Console.WriteLine(batchCheckBox[j].Text);
batchCheckBox[j].Location = new System.Drawing.Point(104 * position, 30);
gpBox[gpcount].Controls.Add(batchCheckBox[j]);
batchCheckBox[j].CheckStateChanged += new System.EventHandler(BatchBoxCheckedChanged);
position++;
count++;
Console.WriteLine(batchCheckBox[j].Name);
k++;
}
position = 1;
gpposition += 100;
}
else
{
count--;
this.Controls.RemoveByKey("lbl" + c.Name);
this.Update();
}
}
int total_batch = 1;
string[] batchname;
private void BatchBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox batchBox = (CheckBox)sender;
//Here I want to store name of checkbox in array
if (batchBox.Checked == true)
{
batchname = new String[total_batch];
total_batch++;
}
else
{
}
}
My problem is solved, I just think about when checkbox can be created dynamically why not groupbox can be created dynamicall as I have done for checkboxes and I modified my code and DONE.
private void RO_SelectedIndexChanged(object sender, EventArgs e)
{
groupBox1.Controls.Clear();
String m = RO.SelectedItem.ToString();
Console.WriteLine(m);
aCommand2 = new OleDbCommand("select * from branch_tbl,region_tbl where branch_tbl.region_id=region_tbl.region_id and region_tbl.region_name LIKE '" + m + "'", main_connection);
aAdapter2 = new OleDbDataAdapter(aCommand2);
ds2 = new DataSet();
aAdapter2.Fill(ds2, "app_info");
ds2.Tables[0].Constraints.Add("pk_bno", ds2.Tables[0].Columns[0], true);
int bran_count = ds2.Tables[0].Rows.Count;
Console.WriteLine(bran_count);
checkBox = new CheckBox[bran_count];
for (int i = 0; i < bran_count; ++i)
{
checkBox[i] = new CheckBox();
checkBox[i].Name = "radio" + Convert.ToString(i);
checkBox[i].Text = ds2.Tables[0].Rows[i][2].ToString();
checkBox[i].Location = new System.Drawing.Point(125 * i, 15);
groupBox1.Controls.Add(checkBox[i]);
checkBox[i].CheckStateChanged += new System.EventHandler(CheckBoxCheckedChanged);
}
gpBox=new GroupBox[bran_count];
}
String str = null;
int count = 1;
int gpcount = 1;
int position = 1;
int gpposition = 110;
//Code for handling event when branch check box is selected or unselected
private void CheckBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
//Label myLabel;
String str = null;
if (c.Checked == true)
{
str = c.Text;
gpBox[gpcount] = new GroupBox();
gpBox[gpcount].Name = "gpBox" + Convert.ToString(count);
gpBox[gpcount].Text = str;
gpBox[gpcount].Location = new Point(5, gpposition);
gpBox[gpcount].AutoSize = true;
this.Controls.Add(gpBox[gpcount]);
aCommand3 = new OleDbCommand("select * from batch_tbl where batch_branch LIKE '" + str + "'", main_connection);
aAdapter3 = new OleDbDataAdapter(aCommand3);
ds3 = new DataSet();
aAdapter3.Fill(ds3, "app_info");
ds3.Tables[0].Constraints.Add("pk_bno", ds3.Tables[0].Columns[0], true);
int batch_count = ds3.Tables[0].Rows.Count;
//filling the groupbox with batch code by generating dynamic checkboxes
for (int i = 0; i < batch_count; ++i)
{
checkBox[i] = new CheckBox();
checkBox[i].Name = "check" + Convert.ToString(i);
checkBox[i].Text = ds3.Tables[0].Rows[i][1].ToString();
Console.WriteLine(checkBox[i].Text);
checkBox[i].Location = new System.Drawing.Point(104 * position, 30);
gpBox[gpcount].Controls.Add(checkBox[i]);
position++;
count++;
}
position = 1;
gpposition += 100;
}
else
{
count--;
this.Controls.RemoveByKey("lbl" + c.Name);
this.Update();
}
}
there can be 8 to 10 batches for each branch, means 8 to 10 checkboxs for each groupboxes. And yes there will be 3 combobox and 1 more checkbox inside each group box.
combobox1 for-> Teachers name coming from table
combobox2 for-> Duration of session coming from table (1 hour, 1.3 hours, 2 hours)
combobox3 for-> Time slot (8:00Am, 8:30 AM, 9:00 AM, 9:30 AM, 10:00 AM, 10:30 AM.. till 8:00 PM)
checkbox for-> Days (S,M,T,W,Th,F,S)
Thanx Tins
For guidance. Yes you are right, but my problem is that I dont know how many branch checkbox user will select, he/she might select 1 or all or 3 out of five. In future if branch increases then check box will for branches will also increase. So, it is not feasiable to add groupboxes for each branches at design time. It should be at run time.
Means groupbox(s) should be generated at runtime as per selection by user for branches.
I have a access database from where I am populating the datagridview on button click event. but what I exactly I want to add record of access database in datagridview when button is clicked. Means on 1st click 1 record should be add in datagridview, on 2nd click another record should be add and so on...
What modification I need to make in my code, please guide me
private void button1_Click(object sender, EventArgs e)
{
aCommand3 = new OleDbCommand("select * from batch_tbl", main_connection);
aAdapter3 = new OleDbDataAdapter(aCommand3);
ds3 = new DataSet();
aAdapter3.Fill(ds3, "app_info");
ds3.Tables[0].Constraints.Add("pk_bno", ds3.Tables[0].Columns[0], true);
int batch_count = ds3.Tables[0].Rows.Count;
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = ds3.Tables[0];
}
Thank you everybody for any advice/suggestion
Dear All
I am trying to create groupbox dynamically and these GB will create on selection on checkbox.
Means I have 5 check boxes now if I select 1st CB then 1 GB with some other dynamic checkbox shall be created, if I select 3rd check then another GB shall be created with few more other checkboxes.
For this I am trying with this code whee I am able to create dynamic checkboxes for fixed groupbox which is already created at design time.
My scenario is - 5 Branches have multiple batches. Now user will choose branch from dynamically checkboxes and on that basis btaches will be displayed in groupbox for each branch.
Branch1 Branch2 Branch3 Branch4 Branch5 if user select 3rd and 5th branch then GB1 will show Branch3's Batches and GB2 shall show Branch5's Batches
Here is the code -
//Check Box for Branches
private void RO_SelectedIndexChanged(object sender, EventArgs e)
{
groupBox1.Controls.Clear();
String m = RO.SelectedItem.ToString();
Console.WriteLine(m);
aCommand2 = new OleDbCommand("select * from branch_tbl,region_tbl where branch_tbl.region_id=region_tbl.region_id and region_tbl.region_name LIKE '"+m +"'", main_connection);
aAdapter2 = new OleDbDataAdapter(aCommand2);
ds2 = new DataSet();
aAdapter2.Fill(ds2, "app_info");
ds2.Tables[0].Constraints.Add("pk_bno", ds2.Tables[0].Columns[0], true);
int bran_count = ds2.Tables[0].Rows.Count;
Console.WriteLine(bran_count);
checkBox = new System.Windows.Forms.CheckBox[bran_count];
for (int i = 0; i < bran_count; ++i)
{
checkBox[i] = new CheckBox();
checkBox[i].Name = "radio" + Convert.ToString(i);
checkBox[i].Text = ds2.Tables[0].Rows[i][2].ToString();
checkBox[i].Location = new System.Drawing.Point(125 * i, 15);
groupBox1.Controls.Add(checkBox[i]);
checkBox[i].CheckStateChanged += new System.EventHandler(CheckBoxCheckedChanged);
}
}
int count = 1;
int position = 1;
//Code for handling event when branch check box is selected or unselected
private void CheckBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
//Label myLabel;
String str = null;
if (c.Checked == true)
{
str = c.Text;
aCommand3 = new OleDbCommand("select * from batch_tbl where batch_branch LIKE '" + str + "'", main_connection);
aAdapter3 = new OleDbDataAdapter(aCommand3);
ds3 = new DataSet();
aAdapter3.Fill(ds3, "app_info");
ds3.Tables[0].Constraints.Add("pk_bno", ds3.Tables[0].Columns[0], true);
int batch_count = ds3.Tables[0].Rows.Count;
//filling the groupbox with batch code by generating dynamic checkboxes
for (int i = 0; i < batch_count; ++i)
{
checkBox[i] = new CheckBox();
checkBox[i].Name = "check" + Convert.ToString(i);
checkBox[i].Text = ds3.Tables[0].Rows[i][1].ToString();
Console.WriteLine(checkBox[i].Text);
checkBox[i].Location = new System.Drawing.Point(104*position, 30);
groupBox2.Text = c.Text;
groupBox2.Controls.Add(checkBox[i]);
position++;
count++;
}
}
else
{
count--;
this.Controls.RemoveByKey("lbl" + c.Name);
this.Update();
}
}
This code very fine but I don't know how many Branch CB will use select, so how can I put GB for each selected branch at desig time, for his I need to genrated GB at runtime on selection of Branch CheckBoxes.
Hello
I am making a win form application on frame work 3.5 using C#.
I am creating dynamic checkboxes depending on the numbers of records in access table. After this I am also able to get the name, text and other properties of dynamically created checkboxes and I am displaying the name of selected checkboexs in dynamically created labels on Form.
My problem is if I uncheck the checkbox, then also name of that checkbox is coming on lable, I want to remove that dynamic label from the form for which checkbox is unchecked.
Example of Form Design
dCeck1 dCheck2 dCheck3 dCheck4 dCheck5 (if dCeck1 dCheck2 dCheck4 dCheck5 is selected)
dLabel1 dLabe2 dLabe4 dLable5 (these label will be displayed)
Now if I unselect dCheck4 then dLabel4 should be removed.
How can I achive this, here is code which I am trying-
private void RO_SelectedIndexChanged(object sender, EventArgs e)
{
groupBox1.Controls.Clear();
String m = RO.SelectedItem.ToString();
Console.WriteLine(m);
aCommand2 = new OleDbCommand("select * from branch_tbl,region_tbl where branch_tbl.region_id=region_tbl.region_id and region_tbl.region_name LIKE '"+m +"'", main_connection);
aAdapter2 = new OleDbDataAdapter(aCommand2);
ds2 = new DataSet();
aAdapter2.Fill(ds2, "app_info");
ds2.Tables[0].Constraints.Add("pk_bno", ds2.Tables[0].Columns[0], true);
int bran_count = ds2.Tables[0].Rows.Count;
Console.WriteLine(bran_count);
checkBox = new System.Windows.Forms.CheckBox[bran_count];
for (int i = 0; i < bran_count; ++i)
{
checkBox[i] = new CheckBox();
checkBox[i].Name = "radio" + Convert.ToString(i);
checkBox[i].Text = ds2.Tables[0].Rows[i][2].ToString();
checkBox[i].Location = new System.Drawing.Point(125 * i, 15);
groupBox1.Controls.Add(checkBox[i]);
checkBox[i].CheckStateChanged += new System.EventHandler(CheckBoxCheckedChanged);
}
}
int count = 1;
int position = 1;
private void CheckBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
Label myLabel;
if (c.Checked == true)
{
count++;
myLabel = new Label();
myLabel.Name="label" + count.ToString();
myLabel.Text = c.Text;
myLabel.Location = new Point(20,65*position);
this.Controls.Add(myLabel);
position++;
}
else
{
return;
}
if(c.CheckState == CheckState.Unchecked)
{
this.Controls.Remove(myLabel);
this.Update();
}
}
Thankyou in advance to all
Hi All
I am trying to generated the dynamic labels depending on the checked checkboxes which are dynamically created.
My .Net frame is 3.5
Here is code for dynamic checkboxes
System.Windows.Forms.CheckBox[] checkBox = new System.Windows.Forms.CheckBox[bran_count];
for (int i = 0; i < bran_count; ++i)
{
checkBox[i] = new CheckBox();
checkBox[i].Name = "radio" + Convert.ToString(i);
checkBox[i].Text = ds2.Tables[0].Rows[i][2].ToString();
checkBox[i].Location = new System.Drawing.Point(125 * i, 15);
groupBox1.Controls.Add(checkBox[i]);
checkBox[i].CheckStateChanged += new System.EventHandler(CheckBoxCheckedChanged);
}
}
private void CheckBoxCheckedChanged(object sender, EventArgs e)
{
//MessageBox.Show();
}
Any guidance is welcome, if possible give some code snippet.
Regards
@Kamran Thank you for your consideration. So you want to say I shall check for each field using php if condition as you shown in your code and concatanate them in $myQuery.
Hello
I have databse in MySQL with 21 fields which are listed below
Field Name Data Type NULL
status text No
roll_no text No
branch_id int(5) No
student_name text No
father_name text No
phone1 text No
phone2 text No
email text No
dob date No
city text No
course_id varchar(5) No
class_id int(2) No
program text No
duration text No
comment text No
admission_year int(4) No
admission_date text No
entryby text No
address text No
admission_no int(4) No
fees int(6) No
Now I am stuck with search process, I bit confused, how can I perform search for different types of conditions/criteria
Few Examples of combinations of condtions
1. Only those records of city=3
2. Only those branch_id=2
3. Only those admission_year='2013'
4. Only those course_id='15'
5. Only those branch_id='2' AND course_id='15'
6. Only those branch_id='2' AND course_id='15' AND city LIKE 'XYZ'
7. Only those admission_year='2012' AND course_id='10' AND duration BETWEEN(2 AND 3)
8. Only those branch_id=2 AND course_id='15' AND student_name LIKE 'XYZ'
8. Only those course_id=7 AND class_id=2 AND father_name LIKE 'XYZ'
My search.php form page is designed, I uploaded the image of form design here but I am confused how can I implement this search options for different situations.
Please give me some guidance and show me the correct way to solve this issue.
Hello
I am trying to send mail to customer with the details of product they brought but the code which I have written not showing the value of variable total_list
Actually I need to send email regarding the product details purchased by user if they purchased more than 1 product then user must get 1 mail with all products detail
For this I am trying to do like this
$cart = $_SESSION['cart'];
$items = explode(',',$cart);
$result = count($items);
$total_list='';
for ($i=0; $i<$result; $i++)
{
//echo $items[$i];
orderconfirm($items[$i]);
}
function orderconfirm($productid)
{
$cus_id = $_SESSION['own_email'];
$pro_id = $productid;
$result = mysql_query("SELECT * FROM products where id = '$pro_id'");
if($row = mysql_fetch_array($result))
{
$subject = $row['Subjects'];
$main_proname = $row['mainproduct'];
$proname = $row['p_name'];
$prodetail = $row['details'];
$proprince = $row['prince'];
}
$holder = $_POST['holder'];
$bank = $_POST['bank'];
$branch = $_POST['branch'];
$ac_no = $_POST['ac_no'];
$cheqdate = $_POST['cheqdate'];
$cheq_no = $_POST['cheq_no'];
$total_amount = $_POST['tota_amount'];
$total_list = $proname.'-'.$main_proname.'-'.$proprince.'<br />';
/* $qry = "INSERT INTO `sales_data`(`cust_id` , `subject` , `pro_id` , `mainproduct` , `pro_name` , `prince` , `bank` , `cheque_no` , `holder_name` , `branch` , `ac_no` , `cheqdate` , `paid` )
VALUES ('$cus_id', '$subject', '$pro_id', '$main_proname', '$proname', '$proprince', '$bank', '$cheq_no', '$holder', '$branch', '$ac_no', '$cheqdate', 'no')";
echo $qry;
$coloer1 = '';
if (!mysql_query($qry))
{
die('Error: ' . mysql_error());
} */
}
echo $total_list;
//unset($_SESSION['cart']);
//$_SESSION['cart']=='';
//echo "1 record added";
//header("Location: thankyou.php");
//exit();
?>
Thank you all
Hi Everybody
I tried and failed to display images of employees in jTable.
I have a MySQL Table which have 4 fields - ID,Name.Phone,Photo(Blob data type). Now I am able to retrive data from this table and display it in JLabel with other data in JTextField, but How can I show the image of employee in jTable if I need a list of all 60 employees details.
MEANS I want jTable sholud show me detail like this
Till now I am able to get see the text data in jTable but not able to get the image. Here what I have done to see the image (Using Netbeans 7.1)
public class mytable
{
Connection con;
PreparedStatement psmt;
public ResultSet rs;
public void mytableFunction() {
final Object[] columnNames=new String[] {"Room No.","Room Type","Bed Type","Tariff Per Room"};
DefaultTableModel dtm=new DefaultTableModel(columnNames,0);
try
{
Class .forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","");
String query = "select * from personaldetail";
psmt = con.prepareStatement(query);
rs=psmt.executeQuery();
int i = 0;
while(rs.next())
{
String var1=rs.getString(1);
String var2=rs.getString(2);
String var3=rs.getString(3);
//String var4=Integer.toString(rs.getInt(4));
dtm.addRow(new Vector());
dtm.setValueAt(var1, i, 0);
dtm.setValueAt(var2, i, 1);
dtm.setValueAt(var3, i, 2);
//dtm.setValueAt(var4, i, 3);
i++;
}
jTable1.setModel(dtm);
jTable1.getColumnModel().getColumn(3).setCellRenderer(new ImageRenderer(rs));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
mytable mtb=new mytable();
mtb.mytableFunction();
}
class ImageRenderer extends DefaultTableCellRenderer
{
ImageIcon format;
ResultSet rs;
public ImageRenderer(ResultSet rs1)
{
rs=rs1;
}
@Override
public Component getTableCellRendererComponent(JTable table,Object value, boolean isSelected,boolean hasFocus, int row, int column)
{
JLabel label = new JLabel();
try{
byte[] imagedata=rs.getBytes(4);
format=new ImageIcon(imagedata);
if (value!=null) {
label.setHorizontalAlignment(JLabel.CENTER);
//value is parameter which filled by byteOfImage
label.setIcon(format);
}
}
catch(Exception ex){}
return label;
}
}
Thank you for any suggestion or help
Hi Every Body
How I can add leading zeros in a number for example
if No. is 4 it should display 0004
if No. is 41 it should display 0041
if No. is 441 it should display 0441
Please give some hint.
Thank you wvery body for helping me. But I have done this in different way - I passed the the current reference of JFrame1 to the constructor of JFrame2 while creating object of JFrame2 in Jframe1 and then I used hat refernce for hiding JFrame1.
JFram1 code -
NavigationFrame nf=new NavigationFrame(this);
nf.setVisible(true);
JFrame2 code-
public NavigationFrame(login O) {
O.setVisible(false);
initComponents();