Hey Friends,
Am pretty new to C# though I don't want that to discourage me.
I have a situation where am using DataGridView and am having a column in my database table namely "msg_status" which has either a value of "0" or "1". The DataGridView should make the rows bold if "msg_status" value is "1" and rest of the rows with value "0" of "msg_status" should be normal.
With that, I don't want "msg_status" to appear in DataGridView. And am only using "msg_status" in database for DataGridView to have something to decide either to show the row in bold or normal. More like generating the feeling of a read/unread email.
My friends, I've searched a lot on internet and came up with these two ideas people had in mind about how to implement...here http://www.c-sharpcorner.com/Forums/Sho ... adID=63866 but it doesn't help in how to make connection with the database and a lot of unanswered issues.
Please help with this, thank you in advance.
Two high hopes here... Neo and Cyclops
How to > DataGridView > Technical Logic >
Re: How to > DataGridView > Technical Logic >
Basically the link you posted explains how to highlight a row/column based on a cell. Following code will help you to connect to database and display a table on the grid.
Also I prefer following code for highlighting.
Code: Select all
private void Form1_Load(object sender, EventArgs e){
string connectionString = GetConnectionString();
SqlConnection con = new SqlConnection(connectionString);
string sqlSelect = "Select * from authors";
SqlCommand cmd = new SqlCommand(sqlSelect,con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
dataGridView1.DataSource = dt;
}
static private string GetConnectionString(){
return "Data Source=localhost; Initial Catalog = pubs; Integrated Security=SSPI"; // SQL Server
//return "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\myDatabase.mdb"; // Access
}
Also I prefer following code for highlighting.
Code: Select all
foreach (DataGridViewRow r in dataGridView1.Rows){
if ( (Convert.ToInt32(r.Cells[1].Value) == 0)){
//Set Row Font to Bold
r.DefaultCellStyle.Font = new Font("Arial", 12, FontStyle.Bold);
}
}
Re: How to > DataGridView > Technical Logic >
Great, can you help with how to implement a solution, please and show an example with a sample database, having a simple table with a few rows and combine all the code to make an example doing what many of us would like to see.
Basically, a datagridview getting data from database (the easy part) but making the rows bold and normal based on content from database, and if we utilize a column for that decision then it shouldn't be displayed in the datagridview.
Sounds doable?
Thanks
Basically, a datagridview getting data from database (the easy part) but making the rows bold and normal based on content from database, and if we utilize a column for that decision then it shouldn't be displayed in the datagridview.
Sounds doable?
Thanks
Re: How to > DataGridView > Technical Logic >
Hey, I can only give you guidance. Not coding
Re: How to > DataGridView > Technical Logic >
Alright, sorry for asking that favor.
Re: How to > DataGridView > Technical Logic >
Okay..okay...I'll try to get you something
Re: How to > DataGridView > Technical Logic >
Here I made a simple app with VS.net 2005. I'm sorry I don't have 2008 with me but hope you could open it with 2008.
Note1: place the MyDB.mdb on the root of C: drive. (i.e.: C:\MyDB.mdb)
Note2: Add exception handling as required
Note1: place the MyDB.mdb on the root of C: drive. (i.e.: C:\MyDB.mdb)
Note2: Add exception handling as required
Re: How to > DataGridView > Technical Logic >
Getting this exception namely The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.
Besides, I changed the path from C: to a sub folder in C:
As windows 7 (x64 bit) isn't letting me put direct files for some security reasons. Though I changed the path in the code too.
Two things, it would be nice if you can show the example using sql server. Secondly, let me know the reason of this error please. So may be I can correct it here.
Thank you Neo.
Besides, I changed the path from C: to a sub folder in C:
As windows 7 (x64 bit) isn't letting me put direct files for some security reasons. Though I changed the path in the code too.
Two things, it would be nice if you can show the example using sql server. Secondly, let me know the reason of this error please. So may be I can correct it here.
Thank you Neo.
Re: How to > DataGridView > Technical Logic >
SQL Server version:
connString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
Make sure you adjust the following line with your database settings.connString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
Re: How to > DataGridView > Technical Logic >
Nice.
Unfortunately, I always used to connect to SQL with Windows Authentication and have forgot the SQL Authentication password. The username is sa but the password is not ......
What to do?
Unfortunately, I always used to connect to SQL with Windows Authentication and have forgot the SQL Authentication password. The username is sa but the password is not ......
What to do?