6
Answers

How to set textbox Length on pictureBox Click

Photo of Rajveer singh

Rajveer singh

7y
222
1
Dear all
                   I have a window application, I'm using text box this text box accept only 6 number but I entering the number by keyboard this validation working fine but enter number PictureBox or button this text box accept more than 6 number. how to fix it.
 
 
by Keyboard insert 
 
 
 
by button insertion 
 
 
 

Answers (6)

1
Photo of Satyapriya Nayak
NA 53k 8m 13y

Attachment comboboxs.rar

Hi Nel,


Refer the below code and change accordingly as per your requirement.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Comboboxs
{
  public partial class Form1 : Form
  {
  string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
  OleDbCommand com;
  OleDbDataAdapter oda;
  DataSet ds;
  string str;

  public Form1()
  {
  InitializeComponent();
  }

  private void Form1_Load(object sender, EventArgs e)
  {
  comboBox1.Items.Add("Choose Color serial No");
  OleDbConnection con = new OleDbConnection(ConnectionString);
  con.Open();
  str = "select * from Color";
  com = new OleDbCommand(str, con);
  OleDbDataReader reader = com.ExecuteReader();
  while (reader.Read())
  {
  comboBox1.Items.Add(reader["ColorserialNo"]);
  }
 
  }

  private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
  comboBox2.Items.Clear();
  OleDbConnection con = new OleDbConnection(ConnectionString);
  con.Open();
  str = "select * from Color where ColorserialNo='" + comboBox1.Text.Trim() + "'";
  com = new OleDbCommand(str, con);
  OleDbDataReader reader = com.ExecuteReader();
  while (reader.Read())
  {
  comboBox2.Items.Add(reader["ColorpartNo"].ToString()); 
  }
  con.Close();
  reader.Close();
 
  }
  }
}



Thanks
If this post helps you mark it as answer
Accepted
0
Photo of Nel
NA 713 955.4k 13y
Thank you very much
0
Photo of Pravin Ghadge
NA 2.5k 358.5k 13y
Nel,

Just use foll lines in place of      conn.Open():
conn.Close();
conn.Open();