Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are looking for <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.drawitem.aspx" rel="nofollow">ListBox.DrawItem Event</a></p> <p>sample code from the MSDN:</p> <pre><code>private void ListBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { // Draw the background of the ListBox control for each item. e.DrawBackground(); // Define the default color of the brush as black. Brush myBrush = Brushes.Black; // Determine the color of the brush to draw each item based // on the index of the item to draw. switch (e.Index) { case 0: myBrush = Brushes.Red; break; case 1: myBrush = Brushes.Orange; break; case 2: myBrush = Brushes.Purple; break; } // Draw the current item text based on the current Font // and the custom brush settings. e.Graphics.DrawString(ListBox1.Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericDefault); // If the ListBox has focus, draw a focus rectangle around the selected item. e.DrawFocusRectangle(); } </code></pre> <p>since you have datatable as datasource you need to find the current datarow </p> <pre><code>DataRowView drv = (DataRowView)this.listBox1.Items[e.Index]; var tableID = drv["tableID"].ToString(); var tableName =drv["tableName "].ToString(); </code></pre> <p>depend on datatype of the <code>tableID</code> you can cast it relevant type and write the condition to change the background color.</p> <p>And also you need to draw the <code>tableName</code> by using <code>DrawString</code> method </p> <pre><code>e.Graphics.DrawString(tableName , e.Font, myBrush, e.Bounds, StringFormat.GenericDefault); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload