5
Answers

Display Specific data in data grid when click on button

Photo of Hemal Joshi

Hemal Joshi

7y
173
1
Hello All,
 
I am create a Windows form which have 2 lables like Start No and End No and according that lable i have put two textboxes now i want to display data when i click on the show button it display data form Start No to End No to data gridview and if no text entered and click on show it will raise an No Record Found Error.
 
EX: Start No: 1
       End No: 5 and then click on Show button it will disply only 1 to 5 records in gridview.
 
Update my Code according to requirement.
 
Design: 
 
 
Here My Code Is:
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace DemoLogin
{
public partial class WorkingMembers : Form
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCon"].ConnectionString);
public WorkingMembers()
{
InitializeComponent();
}
private void btnShow_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from MMMEMBER",con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.ColumnCount = 9;
//Add Columns
dataGridView1.Columns[0].Name = "MNO";
dataGridView1.Columns[0].HeaderText = "MNO";
dataGridView1.Columns[0].DataPropertyName = "MNO";
dataGridView1.Columns[1].Name = "MNAME";
dataGridView1.Columns[1].HeaderText = "MNAME";
dataGridView1.Columns[1].DataPropertyName = "MNAME";
dataGridView1.Columns[2].Name = "MNAME1";
dataGridView1.Columns[2].HeaderText = "MNAME1";
dataGridView1.Columns[2].DataPropertyName = "MNAME1";
dataGridView1.Columns[3].Name = "NOMINY";
dataGridView1.Columns[3].HeaderText = "NOMINY";
dataGridView1.Columns[3].DataPropertyName = "NOMINY";
dataGridView1.Columns[4].Name = "ADD1";
dataGridView1.Columns[4].HeaderText = "ADD1";
dataGridView1.Columns[4].DataPropertyName = "ADD1";
dataGridView1.Columns[5].Name = "CITY";
dataGridView1.Columns[5].HeaderText = "CITY";
dataGridView1.Columns[5].DataPropertyName = "CITY";
dataGridView1.Columns[6].Name = "OP_DT";
dataGridView1.Columns[6].HeaderText = "OP_DT";
dataGridView1.Columns[6].DataPropertyName = "OP_DT";
dataGridView1.Columns[7].Name = "PHONE1";
dataGridView1.Columns[7].HeaderText = "PHONE1";
dataGridView1.Columns[7].DataPropertyName = "PHONE1";
dataGridView1.Columns[8].Name = "CU_SH_AMT";
dataGridView1.Columns[8].HeaderText = "CU_SH_AMT";
dataGridView1.Columns[8].DataPropertyName = "CU_SH_AMT";
dataGridView1.DataSource = dt;
con.Close();
}
}
}
 
 
 

Answers (5)

0
Photo of John
NA 8 0 18y
Ok, how does this translate to the RTB control?

With properties such as Font, ForeColer, BackColor etc. It's simply a matter of selecting the text you want (best done via REGEX) then changing the back and forecolors.

So I think your question is how do I filter incoming ASCII data?  Use REGEX
How do I apply the formatting to the data? Use the RTB.properties and methods.
0
Photo of John
NA 8 0 18y

In the font world there are two types of fonts proportional and non-proportional.  Try using Courier New, it is a non-proportional font.

Your other issues, that of knowing the differences between RTF and regular text files is summed up with this statement: "They are both standards-based ways to present data to the end user."  

Here's the RTF standard.

http://www.microsoft.com/downloads/details.aspx?FamilyID=e5b8ebc2-6ad6-49f0-8c90-e4f763e3f04f&DisplayLang=en 

A Rich Text Box supports this standard.

TextBox is a more simple "standard" that has much less overhead.  I don't know the standard for Textbox support but feel it must be pretty simply  ASCII characters with very simple font control.