Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 4084
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 3, 20222022-06-03T11:41:17+00:00 2022-06-03T11:41:17+00:00

wpf – How to bind dates list datagridtextcolumn with Ivalueconverter

  • 0

[ad_1]

xaml

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:ivaluecon"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Window.Resources>
    <local:YesNoToBooleanConverter x:Key="YesNoToBooleanConverter" />
</Window.Resources>
<Grid>
    <DataGrid x:Name="dg" Grid.Row="1"   AutoGenerateColumns="False"  HorizontalAlignment="Left" Height="163" Margin="25,61,0,0" VerticalAlignment="Top" Width="744">
        <DataGridTextColumn  Binding="{Binding d, Converter={StaticResource YesNoToBooleanConverter}}">
        </DataGridTextColumn>
  </DataGrid>
  <DatePicker x:Name="sdate" HorizontalAlignment="Left" Height="33" Margin="66,312,0,0" VerticalAlignment="Top" Width="148"/>
    <DatePicker x:Name="edate" HorizontalAlignment="Left" Height="33" Margin="272,313,0,0" VerticalAlignment="Top" Width="148"/>
    <Button x:Name="button1" Click="button1_Click" Content="Button" HorizontalAlignment="Left" Height="41" Margin="452,308,0,0" VerticalAlignment="Top" Width="155"/>
</Grid>

I am not able to understand how to bind datelist columns.

class

Public Class YesNoToBooleanConverter

Implements IValueConverter

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        Select Case value.ToString.ToLower
            Case "yes"
                Return True
            Case "no"
                Return False
        End Select
        Return False
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        If TypeOf value Is Boolean Then
            If CBool(value) = True Then : Return "yes"
            Else : Return "no"
            End If
        Else : Return "no"
        End If
    End Function
End Class

Here is my code for generating dateslist columns

Class MainWindow
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
    Dim daysList As DataTable = New DataTable()
    Dim d As DateTime = New DateTime(2020, 12, 1)
    While d <= New DateTime(2020, 12, 14)
        Dim columnName As String = d.ToString("dd.MM")
        daysList.Columns.Add(columnName, GetType(Boolean))
        Dim dd As DataGridTextColumn = New DataGridTextColumn() With {
.Header = columnName,
.Binding = New Binding("[" & columnName & "]")
}
        dg.Columns.Add(dd)
        d = d.AddDays(1)
    End While
    Dim truth = String.Format("{0:on;0;OFF}", True.GetHashCode())
    Dim unTruth = String.Format("{0:on;0;OFF}", False.GetHashCode())
    For r As Integer = 0 To 1 - 1
        Dim row = daysList.NewRow()
        For c As Integer = 0 To daysList.Columns.Count - 1
            row(c) = (c Mod (r + 1)) = 0
        Next
        daysList.Rows.Add(row)
    Next
    dg.ItemsSource = daysList.DefaultView
End Sub
End Class

Someone help me how to bind datelist column with xaml. Please have a look once and give me any example on this issue to fix this. thankyou….

below is the screenshot of dateslist and columns are having True and False I need to change as Yes and No.

enter image description here

[ad_2]

  • 0 0 Answers
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8056 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1842 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1924 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.