Repeater on QT Calendar displays incorrectly when month changed - qt
I am working with the QtQuick controls calendar,
Within this calendar each date is highlighted if the corresponding date is within my database (stored as JSON) - Until now if there is multiple dates within the database, they are displayed only using a single marker (which has worked fine) (noted in the code eg). I am now looking to add a repeater to show multiple highlights, if the date exists more than once in my database.
The repeater is working (code below), but only on the month the calendar is opened in -when you change the visible month in the calendar the repeater either shows the markers on dates from the initial month the calendar was opened in, or not at all?
the code below is an example of my calendar, and below that some of the JSON (I have placed at the bottom for a working example)
Flow {
id: row
anchors.fill: parent
spacing: 10
layoutDirection: Qt.RightToLeft
Calendar {
id: calendar
width: (parent.width > parent.height ? parent.width * 0.6 - parent.spacing : parent.width)
height: (parent.height > parent.width ? parent.height * 0.6 - parent.spacing : parent.height)
selectedDate: new Date()
focus: true
style: CalendarStyle {
id: calendarStyle
navigationBar: Rectangle {
height: Math.round(TextSingleton.implicitHeight * 2.73)
color: "#f9f9f9"
Rectangle {
color: Qt.rgba(1,1,1,0.6)
height: 1
width: parent.width
}
Rectangle {
anchors.bottom: parent.bottom
height: 1
width: parent.width
}
HoverButton {
id: previousMonth
width: parent.height
height: width
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
source: "../assets/leftanglearrow.png"
onClicked: {
control.showPreviousMonth()
}
}
Label {
id: dateText
text: styleData.title
horizontalAlignment: Text.AlignHCenter
font.pixelSize: TextSingleton.implicitHeight * 1.25
anchors.verticalCenter: parent.verticalCenter
}
HoverButton {
id: nextMonth
width: parent.height
height: width
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
source: "../assets/rightanglearrow.png"
onClicked: {
control.showNextMonth()
}
}
}
dayOfWeekDelegate: Item {
height: dp(30)
width: parent.width
Rectangle {
height: parent.height
width: parent.width
anchors.fill: parent
Label {
id: dayOfWeekDelegateText
text: Qt.locale().dayName(styleData.dayOfWeek, Locale.ShortFormat)
anchors.centerIn: parent
}
}
}
dayDelegate: Item {
id: container
readonly property color sameMonthDateTextColor: "#444"
readonly property color selectedDateColor: "#81b1c2"
readonly property color selectedDateTextColor: "#4e4e4e"
readonly property color differentMonthDateTextColor: "#bbb"
readonly property color invalidDatecolor: "#dddddd"
Row {
id: otherUserRow
z: 4
anchors {
top: parent.top; left: parent.left
}
Repeater {
id: repeater
model: {
var found = calendarListModel.filter(
function (element) {
return element.date === styleData.date.getTime();
}
);
if(found === undefined)
return 0;
return repeater.model = found.length;
}
Rectangle {
id: otherUserMarker
width: dp(10)
radius: dp(12)
height: width
color: {
//This works perfectly as the marker is always there simply transparent
var modelObject = calendarListModel.find(
function(obj) {
return obj.date === styleData.date.getTime();
}
);
if (modelObject === undefined)
return "#00000000";
return modelObject.name !== userName + " " + userSurname ? "#e6b89c" : "#e6b89c";
}
}
}
}
Label {
id: dayDelegateText
z: 5
text: styleData.date.getDate()
anchors.centerIn: parent
color: {
var color = invalidDatecolor;
if (styleData.valid) {
color = styleData.visibleMonth ? sameMonthDateTextColor : differentMonthDateTextColor ;
if (styleData.selected) {
color = selectedDateTextColor;
}
}
color ;
}
}
}
}
}
}
A sample of my JSON used as calendarListModel is (extreamly long, but so you can have a full example of changing dates):
[{"date":1555671600000,"name":"Joanne Brown","details":"2 Hour(s) 0m.","status":1},{"date":1558090800000,"name":"Joanne Brown","details":"Full Day","status":1},{"date":1559300400000,"name":"Joanne Brown","details":"Full Day","status":1},{"date":1561114800000,"name":"Joanne Brown","details":"2 Hour(s) 0m.","status":1},{"date":1561719600000,"name":"Joanne Brown","details":"Full Day","status":1},{"date":1563534000000,"name":"Joanne Brown","details":"Full Day","status":1},{"date":1565953200000,"name":"Joanne Brown","details":"Full Day","status":1},{"date":1566558000000,"name":"Joanne Brown","details":"Full Day","status":1},{"date":1554894000000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1555066800000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1555153200000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1559127600000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1557486000000,"name":"Kirsten France","details":"3 Hour(s) 0m.","status":1},{"date":1561806000000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1563534000000,"name":"Kirsten France","details":"5 Hour(s) 30m.","status":1},{"date":1565175600000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1565348400000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1565434800000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1571482800000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1577275200000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1577880000000,"name":"Kirsten France","details":"Full Day","status":1},{"date":1555930800000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1557140400000,"name":"Charlie Davis","details":"2 Hour(s) 0m.","status":1},{"date":1558954800000,"name":"Charlie Davis","details":"2 Hour(s) 0m.","status":1},{"date":1562583600000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1562670000000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1562756400000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1562842800000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1566817200000,"name":"Charlie Davis","details":"2 Hour(s) 0m.","status":1},{"date":1571050800000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1571137200000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1571223600000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1571310000000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1577275200000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1577361600000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1577880000000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1555844400000,"name":"Jenny Ricketts","details":"Full Day","status":1},{"date":1555930800000,"name":"Jenny Ricketts","details":"Full Day","status":1},{"date":1558954800000,"name":"Jenny Ricketts","details":"Full Day","status":1},{"date":1557140400000,"name":"Jenny Ricketts","details":"1 Hour(s) 40m.","status":1},{"date":1563188400000,"name":"Jenny Ricketts","details":"Full Day","status":1},{"date":1566212400000,"name":"Jenny Ricketts","details":"Full Day","status":1},{"date":1566730800000,"name":"Jenny Ricketts","details":"Full Day","status":1},{"date":1566817200000,"name":"Jenny Ricketts","details":"Full Day","status":1},{"date":1567422000000,"name":"Jenny Ricketts","details":"Full Day","status":1},{"date":1555930800000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1556017200000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1556190000000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1556103600000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1557140400000,"name":"Biliana Zutomarkovic","details":"2 Hour(s) 0m.","status":1},{"date":1558954800000,"name":"Biliana Zutomarkovic","details":"2 Hour(s) 0m.","status":1},{"date":1559818800000,"name":"Biliana Zutomarkovic","details":"5 Hour(s) 0m.","status":1},{"date":1560164400000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1563361200000,"name":"Biliana Zutomarkovic","details":"4 Hour(s) 0m.","status":1},{"date":1566817200000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1568545200000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1568631600000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1568718000000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1568804400000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1568890800000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1555671600000,"name":"Katie Prescott","details":"2 Hour(s) 0m.","status":1},{"date":1554375600000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1554462000000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1558090800000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1558177200000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1558609200000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1560078000000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1560423600000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1560510000000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1560596400000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1566126000000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1567162800000,"name":"Katie Prescott","details":"1 Hour(s) 0m.","status":1},{"date":1568372400000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1568458800000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1571396400000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1571482800000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1571828400000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1571914800000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1572001200000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1574251200000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1574337600000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1574424000000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1577275200000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1577361600000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1577880000000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1555671600000,"name":"Tomoko Hirano","details":"7 Hour(s) 20m.","status":1},{"date":1558004400000,"name":"Tomoko Hirano","details":"7 Hour(s) 20m.","status":1},{"date":1558090800000,"name":"Tomoko Hirano","details":"8 Hour(s) 20m.","status":1},{"date":1558436400000,"name":"Tomoko Hirano","details":"8 Hour(s) 20m.","status":1},{"date":1569322800000,"name":"Tomoko Hirano","details":"8 Hour(s) 20m.","status":1},{"date":1569409200000,"name":"Tomoko Hirano","details":"8 Hour(s) 20m.","status":1},{"date":1569495600000,"name":"Tomoko Hirano","details":"8 Hour(s) 20m.","status":1},{"date":1569582000000,"name":"Tomoko Hirano","details":"7 Hour(s) 20m.","status":1},{"date":1569668400000,"name":"Tomoko Hirano","details":"8 Hour(s) 20m.","status":1},{"date":1569927600000,"name":"Tomoko Hirano","details":"8 Hour(s) 20m.","status":1},{"date":1570186800000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1570100400000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1570014000000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1570532400000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1570618800000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1577275200000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1577361600000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1577448000000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1577534400000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1577793600000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1577880000000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1577966400000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1578052800000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1554202800000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1554289200000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1554375600000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1554462000000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1554548400000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1554894000000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1555671600000,"name":"Tania Faenza","details":"2 Hour(s) 0m.","status":1},{"date":1559732400000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1559818800000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1559905200000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1559991600000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1560078000000,"name":"Tania Faenza","details":"7 Hour(s) 20m.","status":1},{"date":1560250800000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1560337200000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1560423600000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1560510000000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1560596400000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1566298800000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1566385200000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1566471600000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1566558000000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1566990000000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1570705200000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1570791600000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1570878000000,"name":"Tania Faenza","details":"8 Hour(s) 20m.","status":1},{"date":1573905600000,"name":"Tania Faenza","details":"7 Hour(s) 0m.","status":1},{"date":1577361600000,"name":"Tania Faenza","details":"10 Hour(s) 20m.","status":1},{"date":1571482800000,"name":"Alessandro Barca","details":"8 Hour(s) 40m.","status":1},{"date":1571655600000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1571742000000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1571828400000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1571914800000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1572087600000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1574942400000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1577275200000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1577361600000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1577880000000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1572782400000,"name":"Alessandro Barca","details":"7 Hour(s) 20m.","status":1},{"date":1577880000000,"name":"Filippos Katsanis","details":"Full Day","status":1},{"date":1556276400000,"name":"Sara Turola","details":"7 Hour(s) 20m.","status":1},{"date":1556362800000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1556449200000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1556535600000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1556794800000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1557140400000,"name":"Sara Turola","details":"1 Hour(s) 0m.","status":1},{"date":1562410800000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1564225200000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1564398000000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1564657200000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1564743600000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1564830000000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1565002800000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1565262000000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1568026800000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1568286000000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1570705200000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1570791600000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1570878000000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1570964400000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1584964800000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1585051200000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1585137600000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1585224000000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1579521600000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1579608000000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1579694400000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1579780800000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1555671600000,"name":"Lisa Duong","details":"3 Hour(s) 20m.","status":1},{"date":1561201200000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1562151600000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1562238000000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1562324400000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1565780400000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1565866800000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1565953200000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1566039600000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1577275200000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1577361600000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1577880000000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1579089600000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1579176000000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1579262400000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1579348800000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1588762800000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1588849200000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1588935600000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1589022000000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1582113600000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1582200000000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1582372800000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1582286400000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1584619200000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1584705600000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1584792000000,"name":"Lisa Duong","details":"Full Day","status":1},{"date":1570273200000,"name":"Tomoko Hirano","details":"Full Day","status":1},{"date":1577275200000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1577361600000,"name":"Biliana Zutomarkovic","details":"Full Day","status":0},{"date":1573387200000,"name":"Joanne Brown","details":"4 Hour(s) 30m.","status":1},{"date":1577966400000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578225600000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578571200000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578484800000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578398400000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578312000000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578744000000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578657600000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578139200000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1578052800000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1608811200000,"name":"Lisa Duong","details":"Full Day","status":"pending"},{"date":1608724800000,"name":"Lisa Duong","details":"Full Day","status":"pending"},{"date":1581422400000,"name":"Charlie Davis","details":"Full Day","status":1},{"date":1579089600000,"name":"Charlie Davis","details":"Half Day (AM)","status":0},{"date":1579089600000,"name":"Charlie Davis","details":"5 Hour(s) 30m.","status":1},{"date":1582459200000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1582545600000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1582632000000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1585479600000,"name":"Biliana Zutomarkovic","details":"Full Day","status":1},{"date":1582804800000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1585652400000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1585738800000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1585911600000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1585998000000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1585825200000,"name":"Katie Prescott","details":"Full Day","status":1},{"date":1577448000000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1577534400000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1577620800000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1577707200000,"name":"Sara Turola","details":"Full Day","status":1},{"date":1577534400000,"name":"Filippos Katsanis","details":"Full Day","status":1},{"date":1577528422774,"name":"Lisa Duong","details":"0 Hour(s) 40m.","status":1},{"date":1585566000000,"name":"Biliana Zutomarkovic","details":"Half Day (AM)","status":1},{"date":1577966400000,"name":"Alessandro Barca","details":"2 Hour(s) 0m.","status":1},{"date":1582200000000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1582113600000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1582027200000,"name":"Alessandro Barca","details":"3 Hour(s) 50m.","status":1},{"date":1586775600000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1586862000000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1586948400000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1587034800000,"name":"Alessandro Barca","details":"Full Day","status":1},{"date":1582372800000,"name":"Mario Cammarata","details":"Full Day","status":1},{"date":1582545600000,"name":"Mario Cammarata","details":"Full Day","status":1},{"date":1582632000000,"name":"Mario Cammarata","details":"Full Day","status":1},{"date":1584619200000,"name":"Mario Cammarata","details":"Full Day","status":1},{"date":1584446400000,"name":"Mario Cammarata","details":"Full Day","status":1},{"date":1584360000000,"name":"Mario Cammarata","details":"Full Day","status":1},{"date":1584273600000,"name":"Mario Cammarata","details":"Full Day","status":1},{"date":1597316400000,"name":"Tania Faenza","details":"Full Day","status":"pending"},{"date":1597402800000,"name":"Tania Faenza","details":"Full Day","status":"pending"},{"date":1597489200000,"name":"Tania Faenza","details":"Full Day","status":"pending"},{"date":1597575600000,"name":"Tania Faenza","details":"Full Day","status":"pending"}]
I have got this working by changing my Repeater {model: {…}} code too;
model: {
var found = calendarListModel.filter(
function (element) {
return element.date === styleData.date.getTime();
}
);
if(found === undefined)
return 0;
return found.length;
// this was changed from directly assigning the repeater.model as
// return repeater.model = found.length
}
Related
How do I save the state of checkbox that is in a listview?
I would like to know how I can save the sate of my checkbox? The checkbox is in a listview of birds. If you click the box it means you have seen that bird and saves the state. I have tried doing it with preferences but don't know if I am on the right track. UPDATE Here is the xaml for the BirdListZA <Frame x:Name="frame" BackgroundColor="#f3f0e9" BorderColor="#f3f0e9" CornerRadius="20" AbsoluteLayout.LayoutBounds="0.5,0.95,0.9,0.9" AbsoluteLayout.LayoutFlags="All"> <ListView x:Name="blistview" BackgroundColor ="#f3f0e9" HasUnevenRows="True" ItemSelected="blistview_ItemSelected" RowHeight="80" AbsoluteLayout.LayoutBounds="0.5,0.95,0.9,0.9" AbsoluteLayout.LayoutFlags="All" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Horizontal"> <Label Text="{Binding BirdNames}" HorizontalOptions="StartAndExpand" VerticalOptions="Center" HeightRequest="40" TextColor="Black" Padding="20,20,0,0" BackgroundColor="#f3f0e9" FontFamily="appfontM"/> <CheckBox x:Name="checkbox" IsChecked="{Binding isChecked}" CheckedChanged="CheckBox_CheckedChanged"/> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </Frame> This is the code behind for the BirdListAZ page public partial class BirdListAZ : ContentPage { private ObservableCollection<birdlistmodel> listBirds; IEnumerable<birdlistmodel> GetBirds(string searchText = null) { var birds = new List<birdlistmodel> { new birdlistmodel (){Id = 1, BirdNames = "Apalis, Bar-throated", isChecked = false }, new birdlistmodel (){Id = 2, BirdNames = "Apalis, Yellow-breasted", isChecked = false}, new birdlistmodel (){Id = 3, BirdNames = "Barbet, Acacia Pied", isChecked = false }, new birdlistmodel (){Id = 4, BirdNames = "Barbet, Black-collared", isChecked = false}, new birdlistmodel (){Id = 5, BirdNames = "Batis, Cape", isChecked = false }, new birdlistmodel (){Id = 6, BirdNames = "Batis, Chinspot", isChecked = false}, new birdlistmodel (){Id = 7, BirdNames = "Bee-eater, European", isChecked = false }, new birdlistmodel (){Id = 8, BirdNames = "Bee-eater, White-fronted", isChecked = false}, new birdlistmodel (){Id = 9, BirdNames = "Bishop,Southern Red", isChecked = false }, new birdlistmodel (){Id = 10, BirdNames = "Bokmakierie", isChecked = false}, new birdlistmodel (){Id = 11, BirdNames = "Boubou, Southern", isChecked = false }, new birdlistmodel (){Id = 12, BirdNames = "Brownbul, Terrestrial", isChecked = false}, new birdlistmodel (){Id = 13, BirdNames = "Bulbul, Dark-capped",isChecked = false }, new birdlistmodel (){Id = 14, BirdNames = "Bunting, Cape", isChecked = false}, new birdlistmodel (){Id = 15, BirdNames = "Bunting, Golden-breasted", isChecked = false }, new birdlistmodel (){Id = 16, BirdNames = "Bushshrike, Gorgeous", isChecked = false}, new birdlistmodel (){Id = 17, BirdNames = "Bushshrike, Grey-headed", isChecked = false }, new birdlistmodel (){Id = 18, BirdNames = "Bushshrike, Olive", isChecked = false}, new birdlistmodel (){Id = 19, BirdNames = "Bushshrike, Orange-breasted", isChecked = false }, }; if (String.IsNullOrWhiteSpace(searchText)) return birds; var lowerBirds = searchText.ToLower(); return birds.Where(c => c.BirdNames.ToLower().StartsWith(lowerBirds)); } public BirdListAZ() { InitializeComponent(); } private void SearchBar_TextChanged(object sender, TextChangedEventArgs e) { blistview.ItemsSource = GetBirds(e.NewTextValue); } private void blistview_ItemSelected(object sender, SelectedItemChangedEventArgs e) { if (((ListView)sender).SelectedItem == null) return; var birds = e.SelectedItem as birdlistmodel; Navigation.PushAsync(new BirdPages(birds.BirdNames, birds.BirdSelect)); ((ListView)sender).SelectedItem = null; } async private void Button_Clicked(object sender, EventArgs e) { await Navigation.PopAsync(); } async private void Button_Clicked_1(object sender, EventArgs e) { await Navigation.PushAsync(new myBirdList()); } protected override void OnAppearing() { base.OnAppearing(); if (string.IsNullOrWhiteSpace(Preferences.Get("listbirds", ""))) { var voels = GetBirds(); listBirds = new ObservableCollection<birdlistmodel>(voels); blistview.ItemsSource = listBirds; } else { string dataString = Xamarin.Essentials.Preferences.Get("listbirds", ""); ObservableCollection<birdlistmodel> listBirds = JsonConvert.DeserializeObject<ObservableCollection<birdlistmodel>>(dataString); blistview.ItemsSource = listBirds; } } private void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e) { var checkbox = (CheckBox)sender; var selectBird = checkbox.BindingContext as birdlistmodel; selectBird.isChecked = e.Value; string json = JsonConvert.SerializeObject(listBirds); Preferences.Set("listbirds", json); } } } The birdlistmodel page class birdlistmodel { public int Id { get; set; } public string Voellist { get; set; } public string BirdNames { get; set; } public Button BirdSelect { get; set; } public bool isChecked { get; set; } }
You could only save the checkbox's state by doing this, and it doesn't tell you which item is checked,and it's even messier if you have multiple choices. If you want to display the selected status when you re-enter the page,you could add a isChecked property to your model. Forexample: the birdlistmodel class: class birdlistmodel { public int Id { get; set; } public string Voellist { get; set; } public string BirdNames { get; set; } public Button BirdSelect { get; set; } public bool isChecked { get; set; } } then in your xaml: <ListView x:Name="blistview" BackgroundColor ="#f3f0e9" HasUnevenRows="True" ItemSelected="blistview_ItemSelected" RowHeight="80" AbsoluteLayout.LayoutBounds="0.5,0.95,0.9,0.9" AbsoluteLayout.LayoutFlags="All" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Horizontal"> <Label Text="{Binding BirdNames}" HorizontalOptions="StartAndExpand" VerticalOptions="Center" HeightRequest="40" TextColor="Black" Padding="20,20,0,0" BackgroundColor="#f3f0e9" FontFamily="appfontM"/> <CheckBox x:Name="checkbox" IsChecked="{Binding isCheckd}" CheckedChanged="CheckBox_CheckedChanged"/> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> in your page.cs: private void checkbox_CheckedChanged(object sender, CheckedChangedEventArgs e) { var checkbox = (CheckBox)sender; var selectBird = checkbox.BindingContext as birdlistmodel; selectBird.isCheckd = e.Value; //if you want save the data and checkbox state,you could save the data as a json string string json = JsonConvert.SerializeObject(xxx);//xxx is the List<birdlistmodel> which you binding to the listview Preferences.Set("listbirds", json); } and when you re-entry the page,you could get the data from the Preferences. string dataString = Xamarin.Essentials.Preferences.Get("listbirds",""); ObservableCollection<birdlistmodel> listBirds = JsonConvert.DeserializeObject<ObservableCollection<birdlistmodel>>(dataString); the first time you entry the page,you should set all the isChecked property to false(because you don't have a choice). var birds = new List<birdlistmodel> { new birdlistmodel (){Id = 1, BirdNames = "Apalis, Bar-throated", isChecked = false}, new birdlistmodel (){Id = 2, BirdNames = "Apalis, Yellow-breasted", isChecked = false}, new birdlistmodel (){Id = 3, BirdNames = "Barbet, Acacia Pied", isChecked = false }, new birdlistmodel (){Id = 4, BirdNames = "Barbet, Black-collared", isChecked = false}, new birdlistmodel (){Id = 5, BirdNames = "Batis, Cape", isChecked = false }, new birdlistmodel (){Id = 6, BirdNames = "Batis, Chinspot", isChecked = false}, new birdlistmodel (){Id = 7, BirdNames = "Bee-eater, European", isChecked = false }, new birdlistmodel (){Id = 8, BirdNames = "Bee-eater, White-fronted", isChecked = false}, new birdlistmodel (){Id = 9, BirdNames = "Bishop,Southern Red", isChecked = false }, new birdlistmodel (){Id = 10, BirdNames = "Bokmakierie", isChecked = false}, new birdlistmodel (){Id = 11, BirdNames = "Boubou, Southern", isChecked = false }, new birdlistmodel (){Id = 12, BirdNames = "Brownbul, Terrestrial", isChecked = false} } when you check the checkbox the checkbox_CheckedChanged will be handle and change the states Update: private ObservableCollection<birdlistmodel> listBirds; //global variable protected override void OnAppearing() { base.OnAppearing(); if (string.IsNullOrEmpty(Preferences.Get("listbirds", ""))) { var voels = GetBirds(); listBirds = new ObservableCollection<birdlistmodel>(voels); blistview.ItemsSource = listBirds; } else { string dataString = Xamarin.Essentials.Preferences.Get("listbirds", ""); listBirds = JsonConvert.DeserializeObject<ObservableCollection<birdlistmodel>>(dataString); blistview.ItemsSource = listBirds; } } then in your private void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e) { var checkbox = (CheckBox)sender; var selectBird = checkbox.BindingContext as birdlistmodel; selectBird.isChecked = e.Value; string json = JsonConvert.SerializeObject(listBirds); Preferences.Set("listbirds", json); }
You will have more than one checkbox, just as you have more than one bird. Use SQL Lite to create a simple database to store the checkbox state for each bird. https://learn.microsoft.com/pt-br/xamarin/get-started/quickstarts/database?pivots=windows
ASP.NET/SQL Not retrieving correct value from database
So I'm trying to create a monopoly web game using asp.net. I was having issues with variables being saved due to the postback, so I've created a database which stores all the info about the players and squares etc. The problem I'm having now however is for some reason the current player ID isn't being stored/retrieved correctly. I apologise for the relatively long wall of code; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; namespace Monopoly_Web { public partial class WebForm1 : System.Web.UI.Page { List<Player> players = new List<Player>(); List<Square> squares = new List<Square>(); Player currentPlayer; Square CurrentSquare; SQLDatabase.DatabaseTable players_table = new SQLDatabase.DatabaseTable("PlayersTable"); SQLDatabase.DatabaseTable squares_table = new SQLDatabase.DatabaseTable("SquaresTable"); SQLDatabase.DatabaseTable gameinfo_table = new SQLDatabase.DatabaseTable("GameInfoTable"); int currentPlayerID = 0; int currentSquareID = 0; int freeParkingAmount = 500; protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { readFromDatabase(); } } //------------------------------------------------------------------------------------------------------------------------------------ // MAIN GAME BUTTONS //------------------------------------------------------------------------------------------------------------------------------------ protected void RollDiceButton_Click(object sender, EventArgs e) { int dice = new Random((int)DateTime.Now.Ticks).Next(1, 7); // Pick a number from 1 to 6 and add it to the current position. diceRoll.Visible = true; diceRoll.Text = "You rolled a " + dice.ToString(); currentPlayer.SetPosition(MovePlayer(dice)); CurrentSquare = squares[currentPlayer.GetPosition()]; updateDisplay(); RollDiceButton.Enabled = false; EndTurnButton.Enabled = true; writeToDatabase(); } protected void BuyButton_Click(object sender, EventArgs e) { writeToDatabase(); } protected void EndTurnButton_Click(object sender, EventArgs e) { diceRoll.Visible = false; buyLabel.Visible = false; payLabel.Visible = false; RollDiceButton.Enabled = true; BuyButton.Enabled = false; EndTurnButton.Enabled = false; //checkBankruptcy(); changeActivePlayer(); currentPlayerLabel.Text = "Current Player: " + currentPlayerID.ToString(); updateDisplay(); writeToDatabase(); } protected void ResumeButton_Click(object sender, EventArgs e) { resumeGame(); RollDiceButton.Enabled = true; EndTurnButton.Enabled = true; StartButton.Visible = false; ResumeButton.Visible = false; } //------------------------------------------------------------------------------------------------------------------------------------ // PLAYER MOVEMENT //------------------------------------------------------------------------------------------------------------------------------------ private int MovePlayer(int dice_value) { currentPlayer.SetPosition(currentPlayer.GetPosition() + dice_value); if (currentPlayer.GetPosition() > (squares.Count - 1)) { currentPlayer.SetPosition(currentPlayer.GetPosition() % squares.Count()); currentPlayer.SetMoney(200); } return currentPlayer.GetPosition(); } private void changeActivePlayer() { currentPlayerID += 1; do { if (currentPlayerID >= players.Count()) { currentPlayerID = 0; } currentPlayer = players[currentPlayerID]; } while (currentPlayer.IsBankrupt() == true); } //------------------------------------------------------------------------------------------------------------------------------------ // START/RESUME GAME //------------------------------------------------------------------------------------------------------------------------------------ private void startGame() { createArrays(); currentPlayer = players[0]; CurrentSquare = squares[0]; if (players_table == null) { foreach (Player player in players) { SQLDatabase.DatabaseRow new_row = players_table.NewRow(); string new_id = players_table.GetNextID().ToString(); new_row["ID"] = new_id; new_row["position"] = player.GetPosition().ToString(); new_row["money"] = player.GetMoney().ToString(); new_row["isInJail"] = player.IsInJail().ToString(); new_row["isBankrupt"] = player.IsBankrupt().ToString(); players_table.Insert(new_row); } } if (gameinfo_table == null) { SQLDatabase.DatabaseRow new_row = gameinfo_table.NewRow(); new_row["ID"] = 1.ToString(); new_row["CurrentPlayerID"] = currentPlayer.GetID().ToString(); new_row["CurrentSquareID"] = CurrentSquare.GetID().ToString(); new_row["FreeParkingAmount"] = freeParkingAmount.ToString(); gameinfo_table.Insert(new_row); } writeToDatabase(); } protected void StartButton_Click(object sender, EventArgs e) { startGame(); updateDisplay(); RollDiceButton.Enabled = true; EndTurnButton.Enabled = true; StartButton.Visible = false; ResumeButton.Visible = false; } private void resumeGame() { readFromDatabase(); updateDisplay(); } //------------------------------------------------------------------------------------------------------------------------------------ // READ/WRITE TO DATABASE //------------------------------------------------------------------------------------------------------------------------------------ private void readFromDatabase() { createArrays(); for (int i = 0; i < 4; i++) { //players[i].SetID(Convert.ToInt32(players_table.GetRow(i)["ID"])); players[i].SetPosition(Convert.ToInt32(players_table.GetRow(i)["position"])); players[i].SetMoney(Convert.ToInt32(players_table.GetRow(i)["money"])); players[i].SetInJail(Convert.ToBoolean(players_table.GetRow(i)["isInJail"])); players[i].SetIsBankrupt(Convert.ToBoolean(players_table.GetRow(i)["isBankrupt"])); } currentPlayerID = Convert.ToInt32(gameinfo_table.GetRow(0)["CurrentPlayerID"]); currentSquareID = Convert.ToInt32(gameinfo_table.GetRow(0)["CurrentSquareID"]); freeParkingAmount = Convert.ToInt32(gameinfo_table.GetRow(0)["FreeParkingAmount"]); currentPlayer = players[currentPlayerID]; CurrentSquare = squares[currentSquareID]; } private void writeToDatabase() { foreach (Player player in players) { SQLDatabase.DatabaseRow prow = players_table.GetRow(player.GetID()); //prow["ID"] = player.GetID().ToString(); prow["position"] = player.GetPosition().ToString(); prow["money"] = player.GetMoney().ToString(); prow["isInJail"] = player.IsInJail().ToString(); prow["isBankrupt"] = player.IsBankrupt().ToString(); players_table.Update(prow); } SQLDatabase.DatabaseRow girow = gameinfo_table.GetRow(0); girow["CurrentPlayerID"] = currentPlayerID.ToString(); girow["CurrentSquareID"] = CurrentSquare.GetID().ToString(); girow["FreeParkingAmount"] = freeParkingAmount.ToString(); } //------------------------------------------------------------------------------------------------------------------------------------ // CREATE PLAYER AND SQUARE ARRAYS //------------------------------------------------------------------------------------------------------------------------------------ private void createArrays() { for (int i = 0; i < 4; i++) { Player player = new Player(i); players.Add(player); } Square square0 = new Square(0, 0, 0, "Go", "go"); Square square1 = new Square(1, 60, 2, "Old Kent Road", "prop"); Square square2 = new Square(2, 0, 0, "Community Chest", "comm"); Square square3 = new Square(3, 60, 4, "Whitechapel Road", "prop"); Square square4 = new Square(4, 200, 0, "Income Tax", "tax"); Square square5 = new Square(5, 200, 25, "Kings Cross Station", "prop"); Square square6 = new Square(6, 100, 6, "The Angel Islington", "prop"); Square square7 = new Square(7, 0, 0, "Chance", "chance"); Square square8 = new Square(8, 100, 6, "Euston Road", "prop"); Square square9 = new Square(9, 120, 8, "Pentonville Road", "prop"); Square square10 = new Square(10, 0, 0, "Visiting Jail", "other"); Square square11 = new Square(11, 140, 10, "Pall Mall", "prop"); Square square12 = new Square(12, 150, 12, "Electric Company", "prop"); Square square13 = new Square(13, 140, 10, "Whitehall", "prop"); Square square14 = new Square(14, 160, 12, "Northumberland Avenue", "prop"); Square square15 = new Square(15, 200, 25, "Marylebone Station", "prop"); Square square16 = new Square(16, 180, 14, "Bow Street", "prop"); Square square17 = new Square(17, 0, 0, "Community Chest", "comm"); Square square18 = new Square(18, 180, 14, "Marlborough Street", "prop"); Square square19 = new Square(19, 200, 16, "Vine Street", "prop"); Square square20 = new Square(20, 0, 0, "Free Parking", "freep"); Square square21 = new Square(21, 220, 18, "Strand", "prop"); Square square22 = new Square(22, 0, 0, "Chance", "chance"); Square square23 = new Square(23, 220, 18, "Fleet Street", "prop"); Square square24 = new Square(24, 240, 20, "Trafalgar Square", "prop"); Square square25 = new Square(25, 200, 25, "Fenchurch Street Station", "prop"); Square square26 = new Square(26, 260, 22, "Leicester Square", "prop"); Square square27 = new Square(27, 260, 22, "Coventry Street", "prop"); Square square28 = new Square(28, 150, 12, "Water Works", "prop"); Square square29 = new Square(29, 280, 22, "Piccadilly", "prop"); Square square30 = new Square(30, 0, 0, "Jail", "jail"); Square square31 = new Square(31, 300, 26, "Regent Street", "prop"); Square square32 = new Square(32, 300, 26, "Oxford Street", "prop"); Square square33 = new Square(33, 0, 0, "Community Chest", "comm"); Square square34 = new Square(34, 320, 28, "Bond Street", "prop"); Square square35 = new Square(35, 200, 25, "Liverpool Street Station", "prop"); Square square36 = new Square(36, 0, 0, "Chance", "chance"); Square square37 = new Square(37, 350, 35, "Park Lane", "prop"); Square square38 = new Square(38, 100, 0, "Super Tax", "tax"); Square square39 = new Square(39, 400, 50, "Mayfair", "prop"); squares.Add(square0); squares.Add(square1); squares.Add(square2); squares.Add(square3); squares.Add(square4); squares.Add(square5); squares.Add(square6); squares.Add(square7); squares.Add(square8); squares.Add(square9); squares.Add(square10); squares.Add(square11); squares.Add(square12); squares.Add(square13); squares.Add(square14); squares.Add(square15); squares.Add(square16); squares.Add(square17); squares.Add(square18); squares.Add(square19); squares.Add(square20); squares.Add(square21); squares.Add(square22); squares.Add(square23); squares.Add(square24); squares.Add(square25); squares.Add(square26); squares.Add(square27); squares.Add(square28); squares.Add(square29); squares.Add(square30); squares.Add(square31); squares.Add(square32); squares.Add(square33); squares.Add(square34); squares.Add(square35); squares.Add(square36); squares.Add(square37); squares.Add(square38); squares.Add(square39); } } } As far as I know the database code I've got works fine as I can resume a game and it will set the player position to be the square they were at before. But for some reason when starting the game it is constantly player 2's turn, and the changeActivePlayer() doesn't seem do anything to help this. I stepped through the code line by line and after clicking the EndTurnButton the playerID had changed but when it came to getting the values from the database it was back to player 2's ID. I'm also not sure why it defaults to player 2, seeing as when I call the start game function I set the current player to players[0] so surely it should be player 1? Any help on this would be appreciated.
junit test for javafx sample login form
please help to test this code using junit #Override public void start(Stage primaryStage) { primaryStage.setTitle("JavaFX Welcome"); GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); Text scenetitle = new Text("Welcome"); scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(scenetitle, 0, 0, 2, 1); Label userName = new Label("User Name:"); grid.add(userName, 0, 1); TextField userTextField = new TextField(); grid.add(userTextField, 1, 1); Label pw = new Label("Password:"); grid.add(pw, 0, 2); PasswordField pwBox = new PasswordField(); grid.add(pwBox, 1, 2); Label status = new Label(); status.setId( "status-label" ); Button btn = new Button("Sign in"); btn.setId("btn"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().add(btn); grid.add(hbBtn, 1, 4); grid.add(status, 1, 8); final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6); // ImageView imageView = new ImageView(new Image(getClass().getResourceAsStream("person.png"), 0, 65, true, true)); //grid.add(imageView, 0, 0,2,2); //btn.setOnAction( ( e ) -> status.setText( computeStatus() ) ); //private String computeStatus() { // return "Name: " + userTextField.getText() + ", Password: " + pwBox.getText(); //} btn.setOnAction(new EventHandler<ActionEvent>() { #Override public void handle(ActionEvent e) { actiontarget.setFill(Color.CORNFLOWERBLUE); actiontarget.setText("Name: " + userTextField.getText() + ", Password: " + pwBox.getText()); } }); Scene scene = new Scene(grid, 300, 275); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); }
MapKit: annotation don't display until zoom the map in iPhone
I expect once clicking the toolbar button like "Mapa", annotations will show in the visible map region. Data are fetched from CoreData (Sqlite). Everything works fine in iPhone Simulator, but when I test the app on my iPhone just some pins are displayed after clicking the button on toolbar and I need to zoom in and out several times to obtain all the pins. the first image (http://www.aerodromoschile.com/IMG_0982.PNG) shows the screen before zoom it several times and the second (http://www.aerodromoschile.com/IMG_0981.PNG) is what I want to get from the begining could you help me? here is the code #import "MapViewController.h" #import "AerodromoAppDelegate.h" #import "Aerodromo.h" #import "DetalleViewController.h" #import <MapKit/MapKit.h> #implementation mapViewController { NSArray *locations; } #synthesize managedObjectContext; #synthesize mapView; - (void)viewDidLoad { [super viewDidLoad]; if (self.managedObjectContext == nil) { self.managedObjectContext = [(AerodromoAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; NSLog(#"After managedObjectContext: %#", self.managedObjectContext); } dispatch_async (dispatch_get_main_queue(), ^{ NSLog(#"Main Thread Code"); NSEntityDescription *entity = [NSEntityDescription entityForName:#"Aerodromo" inManagedObjectContext:self.managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:entity]; NSError *error; NSArray *foundObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error]; if (foundObjects == nil) { NSLog(#"FATAL_CORE_DATA_ERROR(error)"); return; } if (locations != nil) { [self.mapView removeAnnotations:locations]; } locations = foundObjects; self.title = #"Mapa Online"; UIBarButtonItem *showuser = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(showUser:)]; UIBarButtonItem *boton = [[UIBarButtonItem alloc] initWithTitle:#"Boton" style:UIBarButtonItemStyleDone target:self action:#selector(boton2:)]; NSArray *botones = [[NSArray alloc] initWithObjects:showuser, boton, nil]; self.navigationItem.rightBarButtonItems = botones; mapView.delegate = self; // Creamos una coordenada inicial. CLLocationCoordinate2D initialLocation; MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}}; region.center = self.mapView.userLocation.location.coordinate; initialLocation.latitude = self.mapView.userLocation.location.coordinate.latitude; initialLocation.longitude= self.mapView.userLocation.location.coordinate.longitude; // Esto situará el centro del mapa region = MKCoordinateRegionMakeWithDistance(initialLocation, 50000, 50000); [self.mapView setRegion:region animated:NO]; [self.mapView removeAnnotations:self.mapView.annotations]; NSLog(#"antotaciones = %d", locations.count); [self.mapView addAnnotations:locations]; self.mapView.showsUserLocation=TRUE; NSLog(#"fin Thread Code"); }); // termino del queqe //[self.mapView addAnnotations:locations]; //[self updateLocations]; } - (void)showUser:(id)sender{ NSLog(#"Boton1"); MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.mapView.userLocation.coordinate, 50000, 50000); [self.mapView setRegion:[self.mapView regionThatFits:region] animated:NO]; } - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { [self.mapView removeAnnotations:self.mapView.annotations]; [self.mapView addAnnotations:locations]; } - (void)boton2:(id)sender{ NSLog(#"boton 2"); } #pragma mark - MKMapViewDelegate - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { if ([annotation isKindOfClass:[Aerodromo class]]) { static NSString *identifier = #"Aerodromo"; MKAnnotationView *annotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if (annotationView == nil) { annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; annotationView.enabled = YES; annotationView.canShowCallout = YES; //annotationView.animatesDrop = NO; annotationView.image = [UIImage imageNamed:#"aero3.png"]; //annotationView.pinColor = MKPinAnnotationColorGreen; UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; [rightButton addTarget:self action:#selector(showLocationDetails:) forControlEvents:UIControlEventTouchUpInside]; annotationView.rightCalloutAccessoryView = rightButton; } else { annotationView.annotation = annotation; } UIButton *button = (UIButton *)annotationView.rightCalloutAccessoryView; button.tag = [locations indexOfObject:(Aerodromo *)annotation]; return annotationView; } return nil; } - (void)showLocationDetails:(UIButton *)button { NSLog(#"se apreto el boton"); //[self performSegueWithIdentifier:#"EditLocation" sender:button]; } #end EDITED CODE this is the las code that I'm using, I sill have the same problem.... - (void)viewDidLoad { [super viewDidLoad]; if (self.managedObjectContext == nil) { self.managedObjectContext = [(AerodromoAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; NSLog(#"After managedObjectContext: %#", self.managedObjectContext); } UIBarButtonItem *showuser = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(showUser:)]; UIBarButtonItem *boton = [[UIBarButtonItem alloc] initWithTitle:#"Boton" style:UIBarButtonItemStyleDone target:self action:#selector(boton2:)]; NSArray *botones = [[NSArray alloc] initWithObjects:showuser, boton, nil]; self.navigationItem.rightBarButtonItems = botones; self.title = #"Mapa Online"; mapView.delegate = self; // Creamos una coordenada inicial. CLLocationCoordinate2D initialLocation; MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}}; //region.center = //self.mapView.userLocation.location.coordinate; initialLocation.latitude = -33.40;//self.mapView.userLocation.location.coordinate.latitude; initialLocation.longitude= -70.54;//self.mapView.userLocation.location.coordinate.longitude; // Esto situará el centro del mapa region = MKCoordinateRegionMakeWithDistance(initialLocation, 50000, 50000); [self.mapView setRegion:region animated:NO]; self.mapView.showsUserLocation=TRUE; [self.mapView removeAnnotations:self.mapView.annotations]; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ //Anything that is not part of the UI NSLog(#"ASync Thread Code"); NSMutableArray *tempLocations = [[NSMutableArray alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:#"Aerodromo" inManagedObjectContext:self.managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:entity]; NSError *error; NSArray *foundObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error]; if (foundObjects == nil) { NSLog(#"FATAL_CORE_DATA_ERROR(error)"); return; } MKPointAnnotation *location; //If you're not using MKPointAnnotation: replace it for (location in foundObjects) { [tempLocations addObject:location]; } locations = tempLocations.copy; dispatch_sync(dispatch_get_main_queue(), ^{ //Update the UI NSLog(#"Getting back to the UI"); NSLog(#"antotaciones = %d, %#", locations.count, locations); if (locations != nil) { [self.mapView removeAnnotations:self.mapView.annotations]; [self.mapView addAnnotations:locations]; } }); }); NSLog(#"fin Thread Code"); } Thanks for your help wkberg, when I used NSLog(#"antotaciones = %d, %#", locations.count, locations); to know what happen with the data I realized that after the 7th row the NSFetchRequest does not load the data here is the console: 2013-07-16 12:10:18.007 Aerodromo[13922:1207] ASync Thread Code 2013-07-16 12:10:18.045 Aerodromo[13922:907] Getting back to the UI 2013-07-16 12:10:18.090 Aerodromo[13922:907] antotaciones = 351, ( "<Aerodromo: 0x1f0b0040> (entity: Aerodromo; id: 0x1f0ad580 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p1> ; data: {\n Ancho1 = 45;\n Ancho2 = \"\";\n Ancho3 = \"\";\n Ciudad = \"Arica \";\n Desig = SCAR;\n Elev = \"123 -166\";\n FrecTerr = IFR;\n FrecTorre = 1;\n Fuel = JP1;\n Fuel2 = \"AVGAS 100/130\";\n IdAd = 1;\n IndexRegion = 1;\n Larg1 = 2170;\n Larg2 = \"\";\n Larg3 = \"\";\n LatG = 18;\n LatM = 20;\n LatS = 55;\n Latitud = \"-18.349\";\n Limitaciones = \"\";\n Limitaciones2 = \"\";\n Limitaciones3 = \"\";\n LonG = 70;\n LonM = 20;\n LonS = 19;\n Longitud = \"-70.339\";\n Nombre = Chacalluta;\n NumeroPistas = 1;\n Pista1 = \"02-20\";\n Pista2 = \"\";\n Pista3 = \"\";\n RegionOrd = 15;\n Superficie = \"Hormig\\U00f3n\";\n Superficie2 = \"\";\n Superficie3 = \"\";\n Telefono = \"(58) 211116\";\n TieneMetar = 1;\n Uso = \"P\\U00daBLICO\";\n frec = \"<relationship fault: 0x21d8e110 'frec'>\";\n pdf = \"<relationship fault: 0x21d8e460 'pdf'>\";\n})", "<Aerodromo: 0x1f0b0470> (entity: Aerodromo; id: 0x1f098d30 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p2> ; data: {\n Ancho1 = 23;\n Ancho2 = \"\";\n Ancho3 = \"\";\n Ciudad = \"Arica \";\n Desig = SCAE;\n Elev = 328;\n FrecTerr = 0;\n FrecTorre = 0;\n Fuel = \"No Tiene\";\n Fuel2 = \"\";\n IdAd = 2;\n IndexRegion = 1;\n Larg1 = 800;\n Larg2 = \"\";\n Larg3 = \"\";\n LatG = 18;\n LatM = 30;\n LatS = 36;\n Latitud = \"-18.51\";\n Limitaciones = \"\";\n Limitaciones2 = \"\";\n Limitaciones3 = \"\";\n LonG = 70;\n LonM = 17;\n LonS = 21;\n Longitud = \"-70.289\";\n Nombre = \"El Buitre\";\n NumeroPistas = 1;\n Pista1 = \"09-27\";\n Pista2 = \"\";\n Pista3 = \"\";\n RegionOrd = 15;\n Superficie = Asfalto;\n Superficie2 = \"\";\n Superficie3 = \"\";\n Telefono = \"(58) 201500 Anexo 31216\";\n TieneMetar = 0;\n Uso = MILITAR;\n frec = \"<relationship fault: 0x21e711e0 'frec'>\";\n pdf = \"<relationship fault: 0x21e715e0 'pdf'>\";\n})", "<Aerodromo: 0x1f0b0870> (entity: Aerodromo; id: 0x1f0a09c0 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p3> ; data: {\n Ancho1 = 45;\n Ancho2 = \"\";\n Ancho3 = \"\";\n Ciudad = \"Iquique \";\n Desig = SCDA;\n Elev = \"97-157\";\n FrecTerr = \"VFR - IFR\";\n FrecTorre = 1;\n Fuel = JP1;\n Fuel2 = \"AVGAS 100/130\";\n IdAd = 3;\n IndexRegion = 2;\n Larg1 = 3350;\n Larg2 = \"\";\n Larg3 = \"\";\n LatG = 20;\n LatM = 32;\n LatS = 07;\n Latitud = \"-20.535\";\n Limitaciones = \"\";\n Limitaciones2 = \"\";\n Limitaciones3 = \"\";\n LonG = 70;\n LonM = 10;\n LonS = 53;\n Longitud = \"-70.181\";\n Nombre = \"Diego Aracena\";\n NumeroPistas = 1;\n Pista1 = \"19-01\";\n Pista2 = \"\";\n Pista3 = \"\";\n RegionOrd = 1;\n Superficie = \"Hormig\\U00f3n\";\n Superficie2 = \"\";\n Superficie3 = \"\";\n Telefono = \"(57)461200\";\n TieneMetar = 1;\n Uso = \"P\\U00daBLICO\";\n frec = \"<relationship fault: 0x21e71d00 'frec'>\";\n pdf = \"<relationship fault: 0x21e71e70 'pdf'>\";\n})", "<Aerodromo: 0x1f0b0670> (entity: Aerodromo; id: 0x1f0a09a0 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p4> ; data: {\n Ancho1 = 20;\n Ancho2 = 20;\n Ancho3 = \"\";\n Ciudad = \"Pica \";\n Desig = SCKP;\n Elev = 12468;\n FrecTerr = 0;\n FrecTorre = 0;\n Fuel = \"No Tiene\";\n Fuel2 = \"\";\n IdAd = 4;\n IndexRegion = 2;\n Larg1 = 3200;\n Larg2 = 1034;\n Larg3 = \"\";\n LatG = 20;\n LatM = 44;\n LatS = 08;\n Latitud = \"-20.736\";\n Limitaciones = \"\";\n Limitaciones2 = \"\";\n Limitaciones3 = \"\";\n LonG = 68;\n LonM = 41;\n LonS = 42;\n Longitud = \"-68.69499999999999\";\n Nombre = Coposa;\n NumeroPistas = 2;\n Pista1 = \"17-35\";\n Pista2 = \"10-28\";\n Pista3 = \"\";\n RegionOrd = 1;\n Superficie = Asfalto;\n Superficie2 = Tierra;\n Superficie3 = \"\";\n Telefono = \"(57)417777\";\n TieneMetar = 0;\n Uso = PRIVADO;\n frec = \"<relationship fault: 0x21e72b80 'frec'>\";\n pdf = \"<relationship fault: 0x21e72f70 'pdf'>\";\n})", "<Aerodromo: 0x1f0b0a50> (entity: Aerodromo; id: 0x1f0907c0 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p5> ; data: {\n Ancho1 = 30;\n Ancho2 = \"\";\n Ancho3 = \"\";\n Ciudad = \"Pozo Almonte\";\n Desig = SCNV;\n Elev = 3172;\n FrecTerr = 0;\n FrecTorre = 0;\n Fuel = \"No Tiene\";\n Fuel2 = \"\";\n IdAd = 5;\n IndexRegion = 2;\n Larg1 = 1077;\n Larg2 = \"\";\n Larg3 = \"\";\n LatG = 20;\n LatM = 44;\n LatS = \"05,4\";\n Latitud = \"-20.735\";\n Limitaciones = \"\";\n Limitaciones2 = \"\";\n Limitaciones3 = \"\";\n LonG = 69;\n LonM = 37;\n LonS = \"32,6\";\n Longitud = \"-69.626\";\n Nombre = \"Nueva Victoria\";\n NumeroPistas = 1;\n Pista1 = \"09-27\";\n Pista2 = \"\";\n Pista3 = \"\";\n RegionOrd = 1;\n Superficie = Vichufita;\n Superficie2 = \"\";\n Superficie3 = \"\";\n Telefono = \"(57) 413620\";\n TieneMetar = 0;\n Uso = PRIVADO;\n frec = \"<relationship fault: 0x21e739e0 'frec'>\";\n pdf = \"<relationship fault: 0x21e73800 'pdf'>\";\n})", "<Aerodromo: 0x1f0b0c20> (entity: Aerodromo; id: 0x1f0920e0 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p6> ; data: {\n Ancho1 = 18;\n Ancho2 = \"\";\n Ancho3 = \"\";\n Ciudad = \"Antofagasta \";\n Desig = SCGU;\n Elev = 3347;\n FrecTerr = 0;\n FrecTorre = 0;\n Fuel = \"No Tiene\";\n Fuel2 = \"\";\n IdAd = 6;\n IndexRegion = 3;\n Larg1 = 1200;\n Larg2 = \"\";\n Larg3 = \"\";\n LatG = 24;\n LatM = 8;\n LatS = 11;\n Latitud = \"-24.136\";\n Limitaciones = \"\";\n Limitaciones2 = \"\";\n Limitaciones3 = \"\";\n LonG = 69;\n LonM = 49;\n LonS = 43;\n Longitud = \"-69.82899999999999\";\n Nombre = \"Aguas Blancas\";\n NumeroPistas = 1;\n Pista1 = \"13-31\";\n Pista2 = \"\";\n Pista3 = \"\";\n RegionOrd = 2;\n Superficie = Tierra;\n Superficie2 = \"\";\n Superficie3 = \"\";\n Telefono = \"(2) 2063737\";\n TieneMetar = 0;\n Uso = PRIVADO;\n frec = \"<relationship fault: 0x21e744d0 'frec'>\";\n pdf = \"<relationship fault: 0x21e74920 'pdf'>\";\n})", "<Aerodromo: 0x1f0b1020> (entity: Aerodromo; id: 0x1f0a1970 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p7> ; data: {\n Ancho1 = 50;\n Ancho2 = \"\";\n Ancho3 = \"\";\n Ciudad = \"Antofagasta \";\n Desig = SCFA;\n Elev = \"352- 455\";\n FrecTerr = \"VFR - IFR\";\n FrecTorre = 1;\n Fuel = JP1;\n Fuel2 = \"AVGAS 100/130\";\n IdAd = 7;\n IndexRegion = 3;\n Larg1 = 2599;\n Larg2 = \"\";\n Larg3 = \"\";\n LatG = 23;\n LatM = 26;\n LatS = 40;\n Latitud = \"-23.444\";\n Limitaciones = \"\";\n Limitaciones2 = \"\";\n Limitaciones3 = \"\";\n LonG = 70;\n LonM = 26;\n LonS = 42;\n Longitud = \"-70.44499999999999\";\n Nombre = \"Cerro Moreno\";\n NumeroPistas = 1;\n Pista1 = \"01-19\";\n Pista2 = \"\";\n Pista3 = \"\";\n RegionOrd = 2;\n Superficie = Asfalto;\n Superficie2 = \"\";\n Superficie3 = \"\";\n Telefono = \"(55) 269077\";\n TieneMetar = 1;\n Uso = \"P\\U00daBLICO\";\n frec = \"<relationship fault: 0x21e75370 'frec'>\";\n pdf = \"<relationship fault: 0x21e75190 'pdf'>\";\n})", "<Aerodromo: 0x1f0b1770> (entity: Aerodromo; id: 0x1f0a41c0 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p8> ; data: <fault>)", "<Aerodromo: 0x1f0b1f00> (entity: Aerodromo; id: 0x1f0ad660 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p9> ; data: <fault>)", "<Aerodromo: 0x1f0b11e0> (entity: Aerodromo; id: 0x1f071c50 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p10> ; data: <fault>)", "<Aerodromo: 0x1f0b1b50> (entity: Aerodromo; id: 0x1f0a4930 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p11> ; data: <fault>)", "<Aerodromo: 0x1f0b13c0> (entity: Aerodromo; id: 0x1f0a3190 <x-coredata://DEC0D4FE-F4A8-4739-9974-076071695E99/Aerodromo/p12> ; data: <fault>)",
Your dispatching the addAnnotations async. Annotations are part of the UI and should be on the main-thread. The reason they're not added until you zoom the map is because of your regionWillChangeAnimated code. By the time you zoom the async dispatch is finished on the iPhone, but it isn't at the moment when you're adding the annotations in viewDidLoad. To solve your problem with the GCD: In your viewDidLoad do something like this: -(void)viewDidLoad { //Do UI stuff here: //the mapView setup //Region set //and any other UI like: UILabels, UIbuttons etc. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //So now we start the async part: dispatch_async(queue, ^{ //Anything that is not part of the UI //Get your data for the annotations //And now get back to the main_queue sync: dispatch_sync(dispatch_get_main_queue(), ^{ locations = foundObjects; //As in your code //Update the UI NSLog(#"Getting back to the UI"); if (locations != nil) { [self.mapView removeAnnotations:self.mapView.annotations]; //mapView.annotations to remove all... [self.mapView addAnnotations:locations]; } }); }); NSLog(#"End of viewDidLoad"); } From comments: If still not all the annotations show up. Check if you're not calling [self.mapView addAnnotations:locations]; before your locations array is finished. This could be done by regionWillChangeAnimated when adjusting the map to the users locations with your: setRegion:region. NSFetch Problem: Ok as I'm less familiar with NSFetchRequest, please bear with me: I believe your NSFetchRequest isn't populating your locations array with all annotations at once. Try using a NSMutableArray. I've updated the code: NSMutableArray *tempLocations = [[NSMutableArray alloc] init]; //Do your fetchRequest //Then do the following, however I don't know exactly as what your `locations` are stored so you might need to change it a bit: //I believe your annotations are kind of a Aerodromo class? So then: for (Aerodromo *aerodromoAnn in fetchedObjects) { [tempLocations addObject:aerodromoAnn]; } / //Then update your original locations array: locations = tempLocations.copy; //update the main queue again Sorry you'll have to check as I can't test it without the database
How to print datagridview data in c#
I have a datagridview control on my form , I want to print that datagridview, I used following code but it doesn't work PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle(new Point(InvoiceViewergrid.Location.X, InvoiceViewergrid.Location.Y), this.Size)); this.InvokePaint(InvoiceViewergrid, myPaintArgs);
I hope this help you any ways http://www.codeproject.com/Articles/16670/DataGridView-Printing-by-Selecting-Columns-and-Row
You can use this code, hope you've got what you needed here. //Button-Print: private void button5_Click(object sender, EventArgs e) { printPreviewDialog1.ShowDialog(); i = 0; } //GlobalValue. int i = 0; //printDocument private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawString("\r\n\r\n"+ label14.Text + "\r\n" + label11.Text + "\t \t \t \t \t \t" + label6.Text, label11.Font, Brushes.Black, 50, 0); int height = 0; int width = 0; Pen p = new Pen(Brushes.Black,2.5f); //Column1 #region userIDCol e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawRectangle(p, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawString(dataGridView1.Columns[0].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); #endregion //Column2 #region loginTimeCol e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawRectangle(p, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawString(dataGridView1.Columns[1].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); #endregion //Column3 #region logoutTimeCol e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(200 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawRectangle(p, new Rectangle(200 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawString(dataGridView1.Columns[2].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(200 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); #endregion height = 100; while (i < dataGridView1.Rows.Count) { if(height > e.MarginBounds.Height) { height = 100; e.HasMorePages = true; return; } height += dataGridView1.Rows[0].Height; //Column1 e.Graphics.DrawRectangle(p, new Rectangle(100, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); //Column2 e.Graphics.DrawRectangle(p, new Rectangle(100 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); //Column3 e.Graphics.DrawRectangle(p, new Rectangle(200 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(200 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height)); i++; } }