Hi,
In a form I have a datagridview to which I display some info form the db. But I want the first column of dgv to be static. I mean I want to add a new column to the dgv which I have done, now I want to give some names to the first 10 cells of the column 0 such as first, second, third,......., tenth. how to do this?
by default the dgv displays the info from the first row itself. if I want to display it from the second row then how can I do that?
Vimal KandasamyPosted May 15, 2009, 6:33 AM
String[] dt ={ "5/13/2009", "5/13/2009", "5/13/2009", "5/13/2009" };String[] st ={ "9.00", "10.30", "12.00", "14.00" };String[] et ={ "9.30", "11.00", "12.30", "14.30" };dataGridView1.Columns.Add("c2", "Date");dataGridView1.Columns.Add("c3", "STime");dataGridView1.Columns.Add("c4", "ETime");{{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };{String[] row ={ names[i], dt[i], st[i], et[i] };{String[] row ={ "", "", "", "" };sachi vasishtaPosted May 14, 2009, 7:21 AM
I am sorry vimal the adds table in testsample db is only for testing ,I mean first I will develop and test using different dbs and forms, once I have got the successful run then I will copy that code to my development form and for the original db.
vimal for the above problem I have a db table called `scheduleappointment` whose structure is as below
mysql> desc scheduleappointment;
+---------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+----------------+
| scheduleid | int(11) | NO | PRI | NULL | auto_increment |
| scheduledby | varchar(35) | YES | | NULL | |
| scheduledate | varchar(30) | YES | | NULL | |
| provider | varchar(35) | YES | | NULL | |
| starttime | varchar(25) | YES | | NULL | |
| endtime | varchar(25) | YES | | NULL | |
| patientid | varchar(30) | YES | | NULL | |
| reason | varchar(60) | YES | | NULL | |
| priority | varchar(40) | YES | | NULL | |
| scheduledthru | varchar(50) | YES | | NULL | |
| starttime2 | varchar(25) | YES | | NULL | |
| endtime2 | varchar(25) | YES | | NULL | |
+---------------+-------------+------+-----+---------+----------------+
12 rows in set (0.02 sec)
vimal now you can see the columns sheduledate, starttime, and endtime.Now assume this table contains 4 rows of values. Let the date entered in the form2 will be 05/13/2009(U.S format MM/DD/YYYY) and assume the 4 rows values will be
row1--> scheduledate=05/13/2009 starttime=9.00 endtime=9.30(others columns will be as usual)
row2-->scheduledate=05/13/2009 starttime=10.30 endtime=11.00
row3-->scheduledate=05/13/2009 starttime=12.00 endtime=12.30
row4-->scheduledate=05/13/2009 starttime=14.00 endtime=14.30
now vimal when the entered date is 05/13/2009 then the above 4 rows will be selected but when they are displayed in the dgv then they should be displayed as I discribed in my previous posts. And in the First column of dgv I have timings from 9.00 to 16.00. So for the above example the dgv should look like below.
Time Scheduleby Provider ... ... sc..date st.time en.time
9.00 -- empty row --
9.00-9.30 .. ... .. ... 05/13/2009 9.00 9.30
9.30-10.00 -- empty row --
10.00 -- empty row --
10.00-10.30 -- empty row --
10.30-11.00 ... ... .. .. .05/13/2009 10.30 11.00
11.00 -- empty row --
11.00-11.30 -- empty row ----
11.30-12.00 --- empty row ---
12.00 -- empty row ---
12.00-12.30 ... ... ... .... .. 05/13/2009 12.00 12.30
12.30-13.00 -- empty row --
13.00-13.30 --empty row --
14.00 -- empty row ---
14.00-14.30 .. ... .... .... .. 05/13/2009 14.00 14.30
14.30-15.00 .. empty row ...
15.00 --empty row ...
15.00-15.30 .. empty row ....
15.30-16.00 ... empty row.....
please help
thanks
Vimal KandasamyPosted May 14, 2009, 3:24 AM
Sachi,let me check one by one....
what is the result of following code..what it retrives and how many rows it retrives?....
OdbcConnection ocon = new OdbcConnection("Dsn=testsample");ocom.CommandText = string.Format("select * from adds");In select query ,you didnt mention date which selected in form2.make sure The above code retrives scheduling of given day.let me know the output of above code and no of rows..waiting for your reply.
sachi vasishtaPosted May 13, 2009, 6:31 AM
Vimal I am getting the same error. Vimal let me once again explain the scene, plz don't mind.
I have a form(form2 in my case) in which it contains a dgv, a textbox, and a calander. I select a particular date from the calander and that date is placed in the textbox.when a date is placed in the textbox it has to pick some info from the db table called schedule. For schedule table I have entered the values via another form(form7 ......).The entered values are 1.schedular name 2.doctor name 3.patientname 4.date 5.appointment start time 6.appointment end time 7.address 8.city 9.state 10.phone no. and all these values are stored in a db table called schedule. Now in form2 when the date is placed then from db table schedule all values(matching the date placed in the textbox)should occupy the respective rows. for example if the values entered in the form7 for 4 patients for the date 13/05/2009 then in form2 rows which matches the values in the db should show the info from the db table schedule. AND IT should also show the remaining rows empty.
the first column of form2 should be like below
Time -column name
9.00AM -- empty row --
9.00-9.30 -- show values if db contains this value otherwise show empty row --
9.30-10.00 -- '' '' '' '' '' '' '' '' '' '' --
10.00 AM --empty row--
10.00-10.30 -- '' '' '' '' '' '' --
10.30-11.00 -- '' '' '' '' '' '' --
11.00 AM --empty row--
.
.
..
.
4.00 PM -- empty row --
4.00-4.30 -- '' '' ''' '' '' --
4.30-5.00 -- '' '' '' '' '' --
Please help
thanks
Vimal KandasamyPosted May 9, 2009, 6:24 AM
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string var;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//dataGridView1
OdbcConnection ocon = new OdbcConnection("Dsn=testsample");
ocon.Open();
OdbcCommand ocom = new OdbcCommand();
ocom.Connection = ocon;
DataTable dt = new DataTable();
ocom.CommandText = string.Format("select * from adds");
OdbcDataAdapter da = new OdbcDataAdapter(ocom);
da.Fill(dt);
dataGridView1.DataSource = dt;
ocon.Close();
dataGridView1.Rows[0].HeaderCell.Value = "9.00 A.M";
dataGridView1.Rows[1].HeaderCell.Value = "9.00-9.30";
dataGridView1.Rows[2].HeaderCell.Value = "9.30-10.00";
dataGridView1.Rows[3].HeaderCell.Value = "10.00 A.M";
dataGridView1.Rows[4].HeaderCell.Value = "10.00-10.30";
dataGridView1.Rows[5].HeaderCell.Value = "10.30-11.00";
dataGridView1.Rows[6].HeaderCell.Value = "11.00 A.M";
dataGridView1.Rows[7].HeaderCell.Value = "11.00-11.30";
dataGridView1.Rows[8].HeaderCell.Value = "11.30-12.00";
dataGridView1.Rows[9].HeaderCell.Value = "12.00 PM";
dataGridView1.Rows[10].HeaderCell.Value = "12.00-12.30";
dataGridView1.Rows[11].HeaderCell.Value = "12.30-1.00";
dataGridView1.Rows[12].HeaderCell.Value = "1.00 PM";
dataGridView1.Rows[13].HeaderCell.Value = "1.00-1.30";
dataGridView1.Rows[14].HeaderCell.Value = "1.30-2.00";
}
}
}
i.e assign Row headers after data inserted into dgv.and make sure your dataset contain 14 rows.otherwise same error will occur again.
after date and time selected in combobox ,you retrive data from db using select query.It will return a dataset na?..
Dont assign it directly as datasource of dgv.
just get values from it and Insert Empty rows and
Insert value rows and
again insert Empty rows..
At last Insert row headers.
Ex:
9.30 and 9.45 returns values means
Insert empty rows[empty string as content] till 9.30 and 9.45
ie.Insert empty rows for 9.00
and 9.00 to 9.30.
Insert empty rows
after 9.30 to 9.45
i.e for 10.00-11.00 till 1.30-2.00
after that Insert row headers.
sachi vasishtaPosted May 9, 2009, 6:04 AM
vimal I have written the code like below.
namespace
WindowsFormsApplication1{
public partial class Form1 : Form{
string var; public Form1(){
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e){
//dataGridView1dataGridView1.Rows[0].HeaderCell.Value =
"9.00 A.M";dataGridView1.Rows[1].HeaderCell.Value =
"9.00-9.30";dataGridView1.Rows[2].HeaderCell.Value =
"9.30-10.00";dataGridView1.Rows[3].HeaderCell.Value =
"10.00 A.M";dataGridView1.Rows[4].HeaderCell.Value =
"10.00-10.30";dataGridView1.Rows[5].HeaderCell.Value =
"10.30-11.00";dataGridView1.Rows[6].HeaderCell.Value =
"11.00 A.M";dataGridView1.Rows[7].HeaderCell.Value =
"11.00-11.30";dataGridView1.Rows[8].HeaderCell.Value =
"11.30-12.00";dataGridView1.Rows[9].HeaderCell.Value =
"12.00 PM";dataGridView1.Rows[10].HeaderCell.Value =
"12.00-12.30";dataGridView1.Rows[11].HeaderCell.Value =
"12.30-1.00";dataGridView1.Rows[12].HeaderCell.Value =
"1.00 PM";dataGridView1.Rows[13].HeaderCell.Value =
"1.00-1.30";dataGridView1.Rows[14].HeaderCell.Value =
"1.30-2.00"; OdbcConnection ocon = new OdbcConnection("Dsn=testsample");ocon.Open();
OdbcCommand ocom = new OdbcCommand();ocom.Connection = ocon;
DataTable dt = new DataTable();ocom.CommandText =
string.Format("select * from adds"); OdbcDataAdapter da = new OdbcDataAdapter(ocom);da.Fill(dt);
dataGridView1.DataSource = dt;
ocon.Close();
}
}
}
vimal when I debug this it gave me an error saying
ArgumentOutofRangeException was unhandled
Index was out of range.Must be non negative and less than the size of the collection.
Parameter name: index
vimal the thing is when I run the appln the first column should show as I described before and from the second column to ninth column the values I select from the db table patientinfo and when the date entered in the combobox matches the value in the db table patientinfo then that date and time(for instance say 9.30-9.45) should be displayed in the row3 of dgv(row showing 9.30-9.45) but it should not display anything in the rows that shows 9.00AM,10.00AM,11.00AM,.....2.00PM
thanks
Vimal KandasamyPosted May 9, 2009, 3:13 AM
Like
You can assign value for each row header cell.they will be displayed as static. and also you can easily insert your data in dgv.
for insertion of empty row.You try to select values from database based on start and end time for each row one by one.
If it return a value then Insert it into dgv. If it returns null or empty.then insert a row with empty string as cell content.
sachi vasishtaPosted May 9, 2009, 2:37 AM
vimal let me explain the scene clearly
vimal from the second column to nignth column I will display info from db table called patientinfo. The patientinfo contains (name,reason,address,city,state,phone,priority,starttime,endtime,date,email). but I am displaying only 7 columns.The first column structure should be like below(the static structure I need)
Time -- Column Name
9.00 < no tuples displayed here>
9.00-9.15 sachi checkup #40,.. .... ....
9.15-9.30 ...... ........ .....
9.30-9.45 ..... ....... .....
9.45-10.00 ..... ....... .....
10.00 < no tuples displayed here>
10.00-10.15 .... ....... ...... .....
10.15-10.30 .... ...... ......
10.30-10.45
.
.
.
4.00
vimal now the scene is in this form I have a combobox in which I enter the date. ( I have entered other
info such as name, reason, address,......,date,starttime(9.00),endtime(9.15),etc via other forms)now
when I enter the date then the name,reason,etc details should be displayed appropriately. I mean if the
start time and end time is 9.15 and 9.30 in the database and entered date is 8/5/2009 then the person's
details(name,reason,address,etc) should be displayed in the row which shows 9.15-9.30.
Vimal you can also see that the row which shows 9.00,10.00,11.00,.......,4.00 The values should not
be displayed there. How to achieve this
Note: starttime(values left to -) and endtime(values right to -)
thanks
Vimal KandasamyPosted May 9, 2009, 1:06 AM
If you want to display info from 2nd row means initialy insert a blank row i.e row with empty strings.then add new rows.